Need Help understanding Pointer

Reply

Join Date: Jul 2007
Posts: 5
Reputation: gemni7 is an unknown quantity at this point 
Solved Threads: 0
gemni7 gemni7 is offline Offline
Newbie Poster

Need Help understanding Pointer

 
0
  #1
Feb 10th, 2009
Hi all,

I am trying to point a pointer to another pointer and just failed to get resultm here's my failed code,
  1. char *point[] {
  2. "This is One"
  3. "This is Two"
  4. "This is Three"
  5. };
  6.  
  7. char *ptr;
  8.  
  9. ptr = point[2];
  10. 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
Last edited by Ancient Dragon; Feb 10th, 2009 at 8:42 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 5
Reputation: gemni7 is an unknown quantity at this point 
Solved Threads: 0
gemni7 gemni7 is offline Offline
Newbie Poster

Re: Need Help understanding Pointer

 
0
  #2
Feb 10th, 2009
I got it worked i mised ',' in *point declaration
  1. char *point[] {
  2. "This is One",
  3. "This is Two",
  4. "This is Three",
  5. };

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
Last edited by gemni7; Feb 10th, 2009 at 6:51 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,381
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Need Help understanding Pointer

 
0
  #3
Feb 10th, 2009
you also need to add the = symbol
char *point[]  ={
"This is One",
"This is Two",
"This is Three",
};
Last edited by Ancient Dragon; Feb 10th, 2009 at 8:46 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC