Command line arguments...

This is a discussion on Command line arguments... within the C++ Programming forums, part of the General Programming Boards category; would somebody please, tell me a little about what these are... i have done the tutorial for it on the ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    5

    Command line arguments...

    would somebody please, tell me a little about what these are... i have done the tutorial for it on the site, but i don't really know what its talking about... what are the arguments for and where does the input come from

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    if you run your program from the commandline like this
    Code:
    myprog par 1 no
    then argc will be 4
    argv[0] will be "myprog"
    argv[1] will be "par"
    argv[2] will be "1"
    argv[3] will be "no"

    Kurt

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    5
    i still don't understand, what does that mean?

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by AeonMoth View Post
    i still don't understand, what does that mean?
    And I don't understand what you don't understand.
    Kurt

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    > what are the arguments for and where does the input come from
    Have you ever used the command line before now?

    Like typing
    dir
    at the console prompt?

    Well it's just like that, so if you did
    dir /b file.txt

    Then you would get to "/b" and "file.txt" via the argc/argv parameters passed to main()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    11
    Quote Originally Posted by AeonMoth View Post
    would somebody please, tell me a little about what these are... i have done the tutorial for it on the site, but i don't really know what its talking about... what are the arguments for and where does the input come from
    You surely used functions with some arguments before, didn't you? so, let's say you have something like this:
    Code:
    void myFunc(int number, char ch);
    Here you've got 2 arguments, number of type int and ch of type char. You use it within your program, to interact with functions.
    Now let's see this:
    Code:
    int main(int argc, char *argv[])
    { 
        ...
        return 0;
    }
    That's your program, right? You can also give your program some arguments, like any other function but you have to do that from the command line (in DOS-Box).
    Your first parameter (argument) is of type int and it tells you how many arguments the user passed to the program (Attention, program name is included in this count). So when you type
    Code:
    myprog.exe arg1
    argc = 2;
    And ZuK has already written how to use argv. In these example the first argument is agrv[0] = "myprog.exe", the second argv[1] = "arg1" and so on ...

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, 01:11 PM

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