Help~ 错误: 在非结构或联合中请求成员

Smallpoints 2008-10-21 01:10:57
stud.c: 在函数‘main’中:
stud.c:18: 错误: 在非结构或联合中请求成员‘mun’
stud.c:18: 错误: 在非结构或联合中请求成员‘name’
stud.c:18: 错误: 在非结构或联合中请求成员‘course’
stud.c:18: 错误: 在非结构或联合中请求成员‘course’
stud.c:18: 错误: 在非结构或联合中请求成员‘course’


#include <stdio.h>
int main()
{
struct person
{
int mun;
char name[30];
union data
{
float eng;
float math;
float arts;
}course;
}stu[10];
int i;
printf("请输入10个学生数据!\n");
for(i=0;i<10;i++)
scanf("%d%s%f%f%f",&stu.mun,stu.name,&stu.course.eng,&stu.course.math,&stu.course.arts);
}
...全文
1832 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
waydream 2008-10-21
  • 打赏
  • 举报
回复
很明显嘛////
stu是一个person数组。就是一个指针。
&stu是取指针的地址;(&stu)就相当一个void*的指针;所以(&stu.mun)编译器当然不认识啦!!
这么写
stu[0].mun
或者
(*stu).mun

lbh2001 2008-10-21
  • 打赏
  • 举报
回复
联合中一次只能操作一个成员
Smallpoints 2008-10-21
  • 打赏
  • 举报
回复

#include <stdio.h>
int main()
{
struct person
{
int mun;
char name[30];
union data
{
float eng;
float math;
float arts;
}course;
}stu[10];
int i;
printf("请输入10个学生数据!\n");
for(i=0;i <10;i++)
scanf("%d%s%f%f%f",&stu.mun,stu.name,&stu.course.eng,&stu.course.math,&stu.course.arts);
return 0;
}

70,039

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧