Assume I have char **argv.
First, how can I print out all the strings in argv? I tried the following:
char *temp;
temp = *argv; // Now points to the first string?
while (temp != NULL) {
printf("%s ", temp);
temp++;
}
In here, when temp is incremented, it only skips one character. Why is that happening? I know that argv is an array that holds points. Each pointer, points to an array of char*. If so, why isn’t this working? I know that since temp is of type char, incrementing that pointer would increment it by 1 char (or byte). If so, how can I increment the pointer into the next array and print that string out?
It skips only one character because
tempis a pointer to achar. By adding one, you’re telling the compiler to move the pointer on to point at the nextcharin memory.argvis an array of pointers. What you need to do is move on to the next pointer on each iteration. Something like: