问题描述
- 为什么不能实现信息的输入?提示是section下有红线,求改正。谢谢
- #include
#include
#include
#define N 10
union department
{
int cls;
char office[10];
};
struct people
{
char name[10];
int age;
char job;
union deparment section;
}men[N];int main()
{
int i;
for(i=0;i<N;i++){
printf(""input nameagejob and deparmentn"");
gets(men[i].name);
scanf(""%d %c""&men[i].age&men[i].job);
if(men[i].job=='s')
scanf(""%d""&men[i].section.cls);
else
gets(men[i].section.office);
}
printf(""nametage job class/officen"");
for(i=0;i<N;i++)
{
if(men[i].job=='s')
printf(""%st%3d %3c %dn""men[i].namemen[i].agemen[i].jobmen[i].section.cls);
else
printf(""%st%3d %3c %sn""men[i].namemen[i].agemen[i].jobmen[i].section.cls);
}system(""pause"");
}
解决方案
scanf(""%d %c""&men[i].age&men[i].job);改成scanf(""%d %c""&men[i]->age&men[i]->job);
时间: 2024-09-13 21:46:58