Re: How to increment array of pointers to strings



On 04/08/10 18:37, barncat wrote:
I am trying to increment the pointer of this array, similar to
incrementing *argv[]:
*++argv
printf("%s\n", *argv); /* now prints the arg at argv[1]; */
--
code:
char *args[8];
args[0] = "x";
args[1] = "y";
args[2] = "z";

/* if i use:
args++; or
*args++;
i get error:
xxx.c:18: error: wrong type argument to increment
*/
--
how can i increment the pointer and print the contents of the current
location of it?

You're declaring an array of pointers to char. Try walking through the
following code:

#include <stdio.h>

int main(int argc, char *argv[])
{
char * args[8];
int i,j;

args[0] = "tiger";
args[1] = "dog";
args[2] = "horse";
args[3] = "pig";
args[4] = "cougar";
args[5] = "lion";
args[6] = "elephant";
args[7] = "leopard";

i = 0;

while (i < 8)
{
j = -1;
while (args[i][++j] != 0x00);
printf("%s has length %d\n",args[i++],j);
}

return 0;
}

Rgds

Denis McMahon
.