Ancient Dragon was helpful in a way to parse argv(). It brought to mind
a method that suggested to me a way to look at the prefix after finding the expected string. For example (as I interpret it) if you are looking for a prefixed command it could be a command or it might something else like a file name. So for example if a command you are looking at is 'key' and it comes in as '-key' then if you detect the word 'key' you might check to see if the previous character was '-'. In the following
code as a kind of example suggests a way to do this:
This code will print out the '-' if it precedes the string 'key'. If 'key' was typed and the preceding character was not '-' then using
some similar code, one could determine that the word 'key' should probably be treated as a file name or some other case.
Argc- Argument Count. Gives the number of arguments that we pass (includes the program name also) argv- Argument Vector. This is a char. array of strings. These are the argument values itself. So, argv0 is the name of the program itself, and argv1 argvargc-1 will be all our command line arguments. Command Line Arguments in C/C – The special variables. The program will pass the command line arguments to the main function. In C / C, the main function takes in two additional parameters for these arguments. Argc- Argument Count. Gives the number of arguments that we pass (includes the program name also) argv- Argument Vector. If you want to obtain the date in a way that is standard to C or C = then you can use the functions supplied in the header. I leave = it to you to look at what it supplies in whatever C reference material = you have (I'm too tired). For an assignment, I am required to have command line arguments for my C program. I've used argc/argv before (in C) without trouble, but I'm unsure if C style strings are affecting how this works. Here is the start of my main.
Just some random thoughts.
Thanks Ancient Dragon!
Cheers
- 3 Contributors
- forum6 Replies
- 97 Views
- 1 Day Discussion Span
- commentLatest PostLatest Postby ThomsonGB
Recommended Answers
It is customary to have program options to start with either - or /, such as -key or /key. Sometimes you may want an option to be something like '-key=Something', and you may also want to allow for spaces within the string, for example you may type on the commandline …
Jump to Post'>Here's something you may want to look at.
Jump to PostAll 6 Replies
Argc Argv Dev C Treegood Compiler
Argc Argv Dev C Treegood Download
It is customary to have program options to start with either - or /, such as -key or /key. Sometimes you may want an option to be something like '-key=Something', and you may also want to allow for spaces within the string, for example you may type on the commandline prog.exe - key = something
That becomes a little more tricky because in that case the value of argc will be 5 instead of 2.