Thread: argc--; argv++;

  1. #1
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59

    argc--; argv++;

    Hi all, just wondering if someone can explain the reason of having this after main in a program ...

    Code:
    int main(int argc, char **argv)
    {
       argc--; argv++;  // <--- ?
    
      ...
    Just curious

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297

    Smile

    dementia
    Last edited by FillYourBrain; 08-13-2003 at 12:42 PM.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    no, actually it is done with the intention of ignoring the first element of the array. notice the count is what's decremented.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    66
    The first element of argv array is the name of the program being executed, so it is often not needed when parsing for parameters.

    If you do this:

    $> myprog param0 param1

    argc == 3 and
    argv[0] == "myprog"
    argv[1] == "param0"
    argv[2] == "param1"

    After executing argc--; argv++;

    You get:

    argc == 2
    argv[0] == "param0"
    argv[1] == "param1"



    Just a convenience...
    Last edited by achacha; 08-13-2003 at 05:30 PM.

  5. #5
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59
    ahhh, right on, thanks for the insight

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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. help getting a grib on argc and argv
    By elwad in forum C Programming
    Replies: 10
    Last Post: 05-01-2009, 10:13 AM
  2. Using argc and argv data
    By Rad_Turnip in forum C Programming
    Replies: 4
    Last Post: 03-31-2006, 06:09 AM
  3. Converting a argc / argv construct into a va_list
    By chambece in forum C Programming
    Replies: 6
    Last Post: 07-03-2005, 04:47 PM
  4. argc & argv
    By miryellis in forum C Programming
    Replies: 11
    Last Post: 09-19-2004, 11:59 PM
  5. how do i? re: argc - argv
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-11-2004, 10:17 AM