help

This is a discussion on help within the C++ Programming forums, part of the General Programming Boards category; this is just something i dont get... Code: int main ( int argc, char *argv[] )...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    47

    help

    this is just something i dont get...
    Code:
    int main ( int argc, char *argv[] )

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    What exactly dont you get?
    Go to the FAQ and read about command line arguments then come back if you still havent grasped it.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    Its used when you want to run your program with command line arguments

    Like if youve ever seen some programs run like so:

    ./steam -update -username -password

    just an example, not exactly what youd use but just to show, that the hyphenated words like -update are arguments to steam application, the application uses them to run a different way.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    47
    i just dont know what it is or what its used for... the tutoral didnt help

  5. #5
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Its used for exactly what JoshR said.

    If you ever played some older games that didnt have screen resolution/etc option windows, they would use command-line arguments to allow the user to change settings that way. Also used a lot in command prompt programs (-s -b -start -e -i -u -make -exit -shutdown, etc).

    Basicly like if you had a shortcut to "C:\game.exe" -res800x600 -256colors -fullscreen, that would give those commands. Then in int main you would use to check if int argv[1] (resolution option) is == res800x600 (or other ones you might want). Then for the next command, you can check if argv[2] is == to 256colors then in that if statement you do the code to set it to 256colors, you might have an else if == 32colors, etc. Of course that wouldnt be flexible since the commands could be mixed up, so you might need a few || operators in it. Not that I know why you'd use command-line arguments for this example (I'd rather have an options screen).

    Command-line arguments are like the ability to set values to strings that are inside the program, from outside of the program (command-lines).
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    47
    k +thanx that helped

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21