Results 1 to 6 of 6

Thread: command-line extras...

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Cool command-line extras...

    If you know VB, you know that you receive command-line arguments in Command$. How do you get the arguments through C++? Its just a DOS console app, if that makes any difference
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  2. #2
    Member
    Join Date
    Oct 2000
    Posts
    34
    All console apps begin with the function main that looks like this:

    Code:
    int main(int argc, char* argv[])
    {
        return 0;
    }
    argc - Number of elements in the arg array.
    argv - Array of command-line arguments.

    Rippin

  3. #3
    Member
    Join Date
    Oct 2000
    Posts
    34
    I forgot to mention,

    your version of main does not have to have the same signature as the one I wrote in my last post. Alot of times you see main defined like this:
    Code:
    int main(void)
    {
      return 0;
    }
    All you have to do is change your main function to take the parameters listed in my last post.

  4. #4

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    cool, thanks. I'll work with it
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I think the first argument passed in is always the path to the file being executed. I'm not exactly sure, but I think I read that.
    Harry.

    "From one thing, know ten thousand things."

  6. #6
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    argc
    
    An integer specifying how many arguments are passed to the program from the command line. Because the program name is considered an argument, argc is at least 1.
    
    argv
    
    An array of null-terminated strings. It can be declared as an array of pointers to char (char *argv[ ] or wchar_t *argv[ ] for wmain) or as a pointer to pointers to char (char **argv or wchar_t **argv for wmain). The first string (argv[0]) is the program name, and each following string is an argument passed to the program from the command line. The last pointer (argv[argc]) is NULL.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width