0

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.

struct intpair {
		int x ;
		int y ;
	} ;
	
	struct intpair makeintpair(int x, int y) {
	struct intpair temp ;
	temp.x = x ;
	temp.y = y ;
	return temp ;
	}
	struct intpair shared_data = makeintpair(5, 0) ;
	shared_data.y=5;
	 		/* Declare and define data to be be */
	
	 		/* shared by code running on threads. */
	struct intpair *psd ; 				/* Declare & define pointer to shared */
psd = &shared_data ; 	/* data for threads (see below) to use to */
							/* access shared data. */
	printf("%d",psd.y);

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

Thanks

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Luckychap
0

In line:20 ie

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

printf("%d",psd->y);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.