Re: Arrays of pointers to strings?
- From: "Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Feb 2006 10:52:28 -0800
Joe,
I should of thought about it. It makes sence!
I appreciate your help and thanks alot !
--
Best regards
Robert
"Joe" wrote:
.
"Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AE3541E9-1FAF-4C90-83DB-A505EA66B917@xxxxxxxxxxxxxxxx
Hi,
I have tried the following 'C' code:
===============================
char *p[]=
{
"Input ",
"Output ",
"Printer ",
"PaperOut ",
"DiskFull ",
"Write ",
""
};
//Display the first character only
for(i=0; *p[i]; i++)
printf("%c\n",*p[i]);
This:
printf("%c\n",*p[i]);
Is the same as this:
printf("%c\n", p[i][0]);
============================
This displays the first character of every string:
I
O
P
P
D
W
What if I wanted to display the 3rd character of every string instead?
To print the 3rd character:
printf("%c\n", p[i][2]);
Which is the same as this:
printf("%c\n",*(p[i]+2));
I have tried to turn it in a 2 or 3 dimensional array but no luck. I keepelse
getting errors. I have tried a dozen of variations and I don't know what
to try anymore.
Can someone please tell me what I am doing wrong.
It may be easier to see what is happening by splitting out the "get the
address of the right string" from the "display a particular character of a
string".
char* s = p[i]; // get the right string
printf("%c\n",*s); // print first character
printf("%c\n",*(s+0)); // print first character
printf("%c\n",*(s+1)); // print second character
printf("%c\n",*(s+2)); // print third character
--
Best regards
Robert
- References:
- Re: Arrays of pointers to strings?
- From: Joe
- Re: Arrays of pointers to strings?
- Prev by Date: Re: Arrays of pointers to strings?
- Next by Date: Exception handling dilema
- Previous by thread: Re: Arrays of pointers to strings?
- Next by thread: Exception handling dilema
- Index(es):
Relevant Pages
|