Hi all, just wondering if someone can explain the reason of having this after main in a program ...
Just curiousCode:int main(int argc, char **argv) { argc--; argv++; // <--- ? ...
Hi all, just wondering if someone can explain the reason of having this after main in a program ...
Just curiousCode:int main(int argc, char **argv) { argc--; argv++; // <--- ? ...
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
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
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.
ahhh, right on, thanks for the insight
Some more information:
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]