解题思路:
注意事项:结构体中字符串赋值需要用到<string.h>库函数中的strcpy来赋值,主函数中的(struct student s[20];)用来定义结构体中的学生数目的数组,因为不确定输入多少个,所以应该将[ ]中的数字写大点。(20个测试够用)
参考代码:
#include "stdio.h"
#include "string.h"
struct student
{
char xh[20];
char name[20];
int a;
int b;
int c;
};
int main()
{
int x,v,k=0;
scanf("%d",&x);
struct student s[20];//**
char q[20],w[20];int f,g,h;
for (v=0;v<x;v++)
{
scanf("%s %s %d %d %d",q,w,&f,&g,&h);
strcpy(s[k].xh,q);
strcpy(s[k].name,w);
s[k].a=f;
s[k].b=g;
s[k++].c=h;
}
for (int p=0;p<x;p++)
printf("%s,%s,%d,%d,%d\n",s[p].xh,s[p].name,s[p].a,s[p].b,s[p].c);
}
0.0分
1 人评分