#include<stdio.h>
#include<stdlib.h>
struct point
{
int x;
int y;
};
void get(struct point p)
{
printf("Enter the x and y coordinates of your point: ");
scanf("%d %d",&p.x,&p.y);
}
void put(struct point p)
{
printf("(x,y)=(%d,%d)\n",p.x,p.y);
}
int main()
{
struct point pt;
get(pt);
put(pt);
return 0;
}
我正試圖編寫一個程序來獲取用戶的x和y座標,並將它們打印到屏幕上。一旦我輸入x和y座標並出去將它們打印到屏幕上,我會得到:(x,y)=(56,0)。我對結構工作很陌生,所以任何幫助都很好。謝謝。傳遞結構在C中運行
您需要通過引用傳遞結構或將指針傳遞給它。此刻,當您將其發送到get和put函數時,您正在複製整個結構。 – RohinNZ 2014-11-06 23:01:53