Trouble with pointers

Thread Solved
Reply

Join Date: Nov 2008
Posts: 36
Reputation: slimjimmer is an unknown quantity at this point 
Solved Threads: 0
slimjimmer slimjimmer is offline Offline
Light Poster

Trouble with pointers

 
0
  #1
Dec 2nd, 2008
Hi,

In this piece of code in my program I am receiving the following error request for member âyâ in something not a structure or union.

  1. struct intpair {
  2. int x ;
  3. int y ;
  4. } ;
  5.  
  6. struct intpair makeintpair(int x, int y) {
  7. struct intpair temp ;
  8. temp.x = x ;
  9. temp.y = y ;
  10. return temp ;
  11. }
  12. struct intpair shared_data = makeintpair(5, 0) ;
  13. shared_data.y=5;
  14. /* Declare and define data to be be */
  15.  
  16. /* shared by code running on threads. */
  17. struct intpair *psd ; /* Declare & define pointer to shared */
  18. psd = &shared_data ; /* data for threads (see below) to use to */
  19. /* access shared data. */
  20. printf("%d",psd.y);

I can't seem use the data in psd. Can someone please help?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: Trouble with pointers

 
0
  #2
Dec 2nd, 2008
In line:20 ie
  1. printf("%d",psd.y);

psd is used to access y by dot(.) operator which is wrong because psd is a pointer and to access y you must use ->(arrow operator) ie

  1. printf("%d",psd->y);
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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