954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need Help understanding Pointer

Hi all,

I am trying to point a pointer to another pointer and just failed to get resultm here's my failed code,

char *point[] {
"This is One"
"This is Two"
"This is Three"
};

char *ptr;

ptr = point[2];
printf("%s\n", ptr);

I am getting single space printed out instead of "This is Three"
Am I doing wrong, how should I point ptr to point[3]????

Any Help will be appreciated

Rgds,
Will

gemni7
Newbie Poster
5 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

I got it worked i mised ',' in *point declaration

char *point[] {
"This is One",
"This is Two",
"This is Three",
};


But Now compiler is making warning but working absolutly correct
Warning is "warning: assignment discards qualifiers from pointer target type"

Am I still wrong?? or warning is just warning not error

Rgds
Will

gemni7
Newbie Poster
5 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

you also need to add the = symbol

char *point[]  ={
"This is One",
"This is Two",
"This is Three",
};
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You