Re: How to increment array of pointers to strings
- From: Denis McMahon <denis.m.f.mcmahon@xxxxxxxxxxxxxx>
- Date: Wed, 04 Aug 2010 20:52:47 +0100
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
.
- References:
- How to increment array of pointers to strings
- From: barncat
- How to increment array of pointers to strings
- Prev by Date: Re: volatile Info
- Next by Date: Re: How to increment array of pointers to strings
- Previous by thread: Re: How to increment array of pointers to strings
- Next by thread: Re: [OT] Re: What is the best way to navigate #ifdef and #endif in C program
- Index(es):
Relevant Pages
|