int
main(int argc,char **argv){
for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount) {
argCount = 1;
switch (argv[0][1]) {
case 'q':
testnum = atoi(argv[1]);
argCount++;
break;
default:
testnum = 1;
break;
}
}
//...............
my question is what does the argv[0][1] mean and the condition in for() confused me i mean for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount)
//thanks guys….**argv[0][1] should be argv[0][1],thats my mistake not the code writers.
argv[0]represents the name of the program as it was invoked on the command line. If you typed./myprogram --help, thenargv[0]would be “./myprogram”.argv[0][1]will be the second character of that string, ‘/’ in the example above.Let’s see that
for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount):It initializes the loop by doing
argc--thenargv++(argvnow points to the second user parameter string) and argc declares an argument less.The loop is for all arguments
argc>0, and at every iteration, the number of treated argumentsargCountis taken off the number of all argumentsargc. That makes sense.However
switch (**argv[0][1])doesn’t make any sense,argv[0][1]is achar, as seen before, not a pointer, so it cannot be dereferenced.