Thread: Command line arguments

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    29

    Command line arguments

    </code>
    int main(int argc, char * argv[])
    </code>

    Can someone tell me why there is the need of asterick for char *argv[]. Does this make argv[] a pointer?

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    argv is an array of char pointers, that's why there is an asterisk. Frankly speaking I myself doesn't know much about command line arguments, so other's reply will be more helpful.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    Novice
    Join Date
    Jul 2009
    Posts
    568
    argv[] is an array of pointers to string constants.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    60
    Quote Originally Posted by msh View Post
    argv[] is an array of pointers to string constants.
    incorrect !

  5. #5
    Registered User GL.Sam's Avatar
    Join Date
    Aug 2009
    Posts
    88
    incorrect !
    How informative it is... We can only try to guess what is so incorrect about it.
    The only good is knowledge and the only evil is ignorance.
    ~Socrates

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by bvkim View Post
    incorrect !
    No, it's correct.
    It can either be seen as an array of arrays OR
    an array of pointers OR
    a pointer to a pointer.

    In C, they would all be the same in this context.
    An array of pointers would probably be the easiest to understand.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    60
    hahah...

    I like GLSam's answer "How informative it is!", comment of a logical thinker.

    argv[] ??? - NO
    *argv[] <--- YES, this is what I meant

    Just kidding ! NVM!

  8. #8
    1337
    Join Date
    Jul 2008
    Posts
    135
    Basically, it can be written as **argv or *argv[] as argv[] is equivalent to *argv.

    If *argv, it means that it takes a string.

    If **argv, it means that it takes many strings. For example you create a programme called "scan". What you do here is to firstly type in the programme's name (scan) and followed by arguments/parameters when you are using the programme.
    eg. scan -sP -PN 127.0.0.1
    So, scan is the first string, -sP is the second string and so on. if you put *argv or argv[] only, it will only read one string (most likely scan).

    int argc will tel you the position of the parameters. argc = 0 would be scan, argc = 1 would be -sP.

    If you do not understand, please ask further.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by valthyx View Post
    ...if you put *argv or argv[] only, it will only read one string (most likely scan)...
    More likely the entire command line. I know at least Windows doesn't parse the command-line; it simply passes everything to the program. The C runtime hacks the command-line into pieces.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  2. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 06:46 AM
  3. Replies: 10
    Last Post: 09-27-2005, 12:49 PM
  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