结构体指针操作学生成绩
程序员文章站
2022-06-17 17:18:38
...
结构体指针操作学生成绩
#include <stdio.h>
#include <stdlib.h>
struct Student
{
int score;
char *name; // char name[128];
};
int main()
{
int i;
int a ;
printf("请输入总人数;\n");
scanf("%d",&a);
//struct Student stus[3];
//struct Student *p = stus;
struct Student *p = (struct Student *)malloc(a*sizeof(struct Student ));
for(i=0;i<a;i++){
printf("请输入名字;\n");
p->name = (char *)malloc(128);
scanf("%s",(p->name));
printf("请输入分数;\n");
scanf("%d",&(p->score));
p++;
}
p = p - a;
for(i=0;i<a;i++){
printf("名字;%s,分数;%d\n",p->name,p->score);
p++;
}
system("pause");
return 0;
}
也没什么好讲的,做个笔记。