command line args

This is a discussion on command line args within the C Programming forums, part of the General Programming Boards category; Hi, every where I see Code: int main(int argc, char *argv[]) if i write Code: int main(int a, char **b) ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    13

    command line args

    Hi,

    every where I see

    Code:
    int main(int argc, char *argv[])

    if i write

    Code:
    int main(int a, char **b)
    is this OK to write like this..
    or any problem is there... Please explain.

    thanx

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    Both are correct
    The function called at program startup is named main. The implementation declares no
    prototype for this function. It shall be defined with a return type of int and with no
    parameters:
    int main(void) { /* ... */ }
    or with two parameters (referred to here as argc and argv, though any names may be
    used, as they are local to the function in which they are declared):
    int main(int argc, char *argv[]) { /* ... */ }
    or equivalent;**) or in some other implementation-defined manner.

    **Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as
    char ** argv, and so on.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    13
    thanks for ur reply...

    here what i want to know is

    whether "argc" and "argv" are keywords...or I can use any names....
    I got this doubt just now and I dont have C compiler to test it.

    thanx

  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    They arent keywords you can call them whatever you want.
    But if you had read the post of Wledge carefully you shouldof know that.

    quote from Wledge's quote
    referred to here as argc and argv, though any names may be
    used, as they are local to the function in which they are declared):

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Don't, whatever you do, read this.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer confusion
    By Blackroot in forum C++ Programming
    Replies: 11
    Last Post: 09-12-2007, 12:44 AM
  2. Replies: 2
    Last Post: 10-24-2005, 01:32 PM
  3. Replies: 1
    Last Post: 06-29-2004, 05:23 PM
  4. Multiple Command Line Args
    By mart_man00 in forum C Programming
    Replies: 10
    Last Post: 08-16-2002, 02:15 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

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