int main(int argc, char **argv) {

char **myargv = argv + 1;
while (myargv[0] && myargv[0][0] == '-') {
if (strcmp(myargv[0], "-d") == 0) {
myargv++;
continue;
}
exit(1);
}


argc -= (myargv - argv);
argv = myargv;

Hi ,
I am new to C programming . I understood the above arguments to main are for command line purposes . But the next line contains a character double pointer to argv.
I didnt understand, what will be stored in myargv?
and the while loop condition have two dimensional array this to confuses me.
could any one tell me what will be the final value of argv?

thanks in advance ..

I didnt understand, what will be stored in myargv?
could any one tell me what will be the final value of argv?

thanks in advance ..

What's stored? A double pointer to char, would it make more sense written like this

char **myargv = &argv[1];

What's the final value? Depends on what the caller of the program sends as command line arguments.

hi gerard thanks for that ,
]but could you tell me what does the conditions in the while does ,why are they using a two dimensional array?

I won't handle your condition this way. I would check argc first to see if it indicates a second command line argument. If you find that you have a second command line argument then start parsing the value.

Like so

#include <stdio.h>

int main(int argc, char**argv)
{
	if (argc >= 1)/*check for second argument*/
		fprintf(stdout, "%s\n", argv[1]);
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.