Well, the problem is rather general c than c++ oriented, so i hope you won't mind.
I have to write an application that gets what to do via argv[] values. And so, i've made a loop with getopt functions. When there is an argument passed that isn't on the list, the usage() function is called.
And there's a small problem.
When i try to pass --help or --? parameter to explicitly call the usage() function, it gives a illegal option problem. So, what shall i change here to accept single --help/--? ?
I could check for that at the very beginning of the main() block, but then, i'm curious how to do that in that loop.
The problematic code itself:
1 2 3 4 5 6 7 8 9 10 11 12 13
while ((ch = getopt(argc, argv,"vnabf:h")) != -1){
switch (ch) {
case'v': whatever breakcase'n': even more whatever breakcase'a': yeah breakcase'b': breakcase'f': get optarg and breakcase'h': breakcase'?': call help?
default:
usage();
}
}
Then, what shall i do then, helios? Is there any other way than manually parsing through argv table?
Well, i made as i've said in the main post, about checking the --help at the very beginning of the application, of course that works, but i'm just curious how it should be done, and whether getopt is capable of doing that, and whether there is linux alternative to getopt that would work with GNU-style arguments.