对error C2079: 'stu' uses undefined struct 'Students'的解释

以下是错误程序源代码举例(其实是我自己在学习过程中出现的错误):

#include <stdio.h>
struct Date
{
	int year;
	int month;
};
struct Student
{
	char sno[11];
	char name[10];
	int Gshu;
	int Ccheng;
	int Yyu;
	float Average;
	Date birthday;
};
int main()
{
	struct Students stu;
	printf("输入学号:");
	gets(stu.sno);
	printf("输入姓名:");
	gets(stu.name);
	printf("高数成绩:");
	scanf("%d",&stu.Gshu);
	printf("C程成绩:");
	scanf("%d",&stu.Ccheng);
	printf("英语成绩:");
	scanf("%d",&stu.Yyu);
	stu.Average=(stu.Gshu+stu.Ccheng+stu.Yyu)/3.0;
	printf("输入出生年月");
	scanf("%d%d",&stu.birthday.year,&stu.birthday.month);
	printf("学号 姓名 高数 C程 英语 平均成绩 出生年月\n");
	printf(" %11s",stu.sno);
	printf("   %6s",stu.name);
	printf(" %3d %3d %3d %4.1f",stu.Gshu,stu.Ccheng,stu.Yyu);
	printf("    %d年%d月\n",stu.birthday.year,stu.birthday.month);
	return 0;
}

运行错误如下:
error C2079: 'stu' uses undefined struct 'Students'

这个地方的错误是将上文中的Student误写为Students,于是出现了未定义的错误,改正方式只要将Students改为Student就可以解决。但是如果不是因为笔误,而是正确的写出了Student,但是仍然为错误的话,解决方法是检查上文中有没有对Student进行定义(struct),通过对Student定义即在前文(主函数外)添加:struct Student,就可以解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值