解题思路:
1.利用结构体储存学生信息
2.利用malloc 申请内存空间
3.利用指针people 遍历内存信息并输出
注意事项:
用getchar()去除' \n '
参考代码:
#include<stdio.h>
#include<malloc.h>
typedef struct _Student
{
char num[10];
char name[10];
int Chinese;
int Maths;
int English;
}Student;
int main()
{
int n = 0;
scanf("%d", &n);
Student* people = (Student*)malloc(sizeof(Student) * n);
for (int i = 0; i < n; i++)
{
scanf("%s %s %d %d %d", (people+i)->num, (people + i)->name, &(people + i)->Chinese, &(people + i)->Maths, &(people + i)->English);
getchar();
}
for (int i = 0; i < n; i++)
{
printf("%s,%s,%d,%d,%d\n", (people + i)->num, (people + i)->name, (people + i)->Chinese, (people + i)->Maths, (people + i)->English);
}
free(people);
return 0;
}
0.0分
3 人评分