943,917 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 444
  • C RSS
Feb 10th, 2009
0

Need Help understanding Pointer

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gemni7 is offline Offline
5 posts
since Jul 2007
Feb 10th, 2009
0

Re: Need Help understanding Pointer

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gemni7 is offline Offline
5 posts
since Jul 2007
Feb 10th, 2009
0

Re: Need Help understanding Pointer

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Individual Sector Reading in C
Next Thread in C Forum Timeline: Prgramming in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC