Thread: command line arguments

  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    dehradun
    Posts
    5

    Unhappy command line arguments

    please can anyone tell whether i can use command line arguments in c on windows xp
    in the tutorial it was mentioned that dos and linux are command line os
    is windows also a command line os

  2. #2
    Registered User
    Join Date
    Aug 2007
    Posts
    81
    start->run and type "cmd" and hit enter.

    EDIT: you also want to know how to pass arguments via the command line?

    Each argument is delimited by a space, so it's like

    myprogram.exe argument1 argument2 etc...

  3. #3
    Registered User
    Join Date
    Aug 2007
    Location
    dehradun
    Posts
    5
    then?

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    81
    What do you mean then? That is how you pass arguments via the command line. To answer your question about windows being a command line OS. No it really isn't. The MSDOS in windows XP isn't a fully functional DOS, it's some kind of abstraction that supports minimal shell features.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Location
    dehradun
    Posts
    5
    the code for my program is this

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    int main(int argc,char *argv[] )
    {
        printf("%d\n",argc);
        printf("%s",**argv);
        int c;
        scanf("%d",c);
        return 0;
    }

    but when i do as u say it says 'hello.exe' is not recognized as an internal or an external command

  6. #6
    Registered User
    Join Date
    Jul 2006
    Posts
    162
    are you starting c++ at main() arguments? there might be a lot more you want to learn first, i suggest going through some tutorials before doing this part.

    not to mention you need to learn about software in general, and how to use the command line...

    it's like wanting to be an astronaut and starting at the pilot seat of the space shuttle before anything else. (lol ok this analogy is extreme, but the contrast is too glaring to miss the point.)
    Last edited by simpleid; 08-15-2007 at 08:00 AM.

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    81
    I agree with simple but to be a sport:

    Code:
    #include<stdio.h>
    int main(int argc,char *argv[] )
    {
        int i;
        printf("There are &#37;d arguments\n",argc);
        for (i=0; i < argc; i++) 
           printf("%s ", *argv++);
        return 0;
    }
    /** OUTPUT **
     *
     * >hello.exe one two three four
     * There are 5 arguments. 
     * hello.exe one two three four
     *
     */
    Last edited by keira; 08-15-2007 at 08:21 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  3. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 06:46 AM
  4. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 10:48 AM
  5. registry, services & command line arguments.. ?
    By BrianK in forum Windows Programming
    Replies: 3
    Last Post: 03-04-2003, 02:11 PM