![]() |
| | #1 | ||
| Day Dreamer Join Date: Apr 2007
Posts: 45
| Variable Arguments through Command Line Code: if(argc!=1) Quote:
Quote:
Implementing a limit on the number of parameters that the user can send (there certainly has to be one as the code cant keep processing all possible values of argv[], I know argv[] is not of constant size anyway.) I have never seen va_args being used to work on arguments passed from the command line.
__________________ I would love to change the world but they dont give me the source code! | ||
| zombiezparadize is offline | |
| | #2 |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,139
| argc = Argument count (the amount of arguments in the argv) argv = Argument Vector (holds arguments) I don't get your question, you want to stay in bounds? That's easy -- just keep within 0 to argc - 1 If you want to check if element n exists, Code: if(n < argc)
n exists!
Last edited by zacs7; 05-06-2008 at 06:18 AM. |
| zacs7 is offline | |
| | #3 |
| Day Dreamer Join Date: Apr 2007
Posts: 45
| On going through the post again, yeah I agree it is asking a pretty vague or rather a question that is too obvious. I was more concerned about the the comparison. If the programmer were to write what he wrote Code: if(argc!=1) Sorry about the vague post. Too many things in mind cause such blunders.
__________________ I would love to change the world but they dont give me the source code! |
| zombiezparadize is offline | |
| | #4 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Actually, if(argc != 1) is "is there any arguments". argc should never be able to be negative, and 0 is invalid, as argv[0] is the name of the program (or something along those lines). However, there should probably be some "else" or similar to that if-statement - but I guess it is valid to just "do nothing" (or "do some default") if there are no arguments. As long as argument access is within the bounds of 0 ... (argc-1), then it's valid. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #5 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,354
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #6 | |
| Day Dreamer Join Date: Apr 2007
Posts: 45
| Quote:
Which means when there are no arguments passed to the program the code will merrily throw SIGSEGV as it is going to access Code: *++argv /* As used by the programmer though I hate writing such operator precedence dependent code. I find it very unreadable*/ @laserlight: argc=0 . I didn't know that one. Thanks!
__________________ I would love to change the world but they dont give me the source code! | |
| zombiezparadize is offline | |
![]() |
| Tags |
| "command line", "variable arguments" |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Functions with variable argument count.. | 39ster | C++ Programming | 3 | 04-11-2009 09:18 AM |
| Screwy Linker Error - VC2005 | Tonto | C++ Programming | 5 | 06-19-2007 02:39 PM |
| Problem with a char variable set as a letter | 7smurfs | C++ Programming | 6 | 12-10-2004 01:25 PM |
| Core Dump with Variable Arguments | penney | C Programming | 1 | 06-20-2003 10:11 AM |
| (Variable Arguments,...) | Sebastiani | C Programming | 3 | 09-07-2001 10:44 AM |