问题遇到的现象和发生背景
MOOC上翁恺的C语言进阶课,3.2.2结构与函数,完全是抄的代码,不知道为什么跑不出来结果
用代码块功能插入代码,请勿粘贴截图
#include <stdio.h>
struct point { //定义结构全局变量
int x;
int y;
};
struct point* getStruct (struct point*);//函数声明
void output(struct point);
void print(const struct point *p);
int main()
{
struct point y = {0,0};
getStruct(&y);
output(y);
output(*getStruct(&y));
print(getStruct(&y));
return 0;
}
struct point* getStruct (struct point *p)//参数是指针 函数用于读入结构
{
scanf("%d",&p->x);
scanf("%d",&p->y);
printf("1.%d,%d\n",p->x,p->y);
return p;
}
void output(struct point p) //输出结构
{
printf("2.%d,%d\n",p.x,p.y);
}
void print(const struct point *p) //用指针输出结构
{
printf("3.%d,%d\n",p->x,p->y);
}
运行结果及报错内容
输入56 77
输出
1.56,77
2.56,77
可以编译通过没有报错,运行时只输出了两次,第二个output函数和print函数没有输出内容
我想要达到的结果
按理说应该将结构输出四次的,但是只输出了两次。C语言初学者,希望自己没有提出太nc的问题,求指点