要实现一个小型的学生管理系统就必须要学会使用结构体来进行数据的存储和使用,我就把自己用结构体写出来的一个小的学生信息录入系统放在下面了。
#include<stdio.h>
struct STU //构造结构体
{
int stu_id; //学号
char name[10]; //姓名
int score[3]; //成绩(数组)
};
int main()
{
int i=0;
struct STU student1={12,"Kelvin",89,87,101}; //初始化结构体
struct STU student2;
printf("请输入第二个学生的信息:\n 学号:");
scanf("%d",&student2.stu_id); //用.操作符访问数据(赋值)
printf("姓名:");
scanf("%s",&student2.name);
printf("成绩:");
for(i=0;i<3;i++)
scanf("%d",&student2.score[i]);
printf("学号:%d\n姓名:%s\n,成绩:%d,%d,%d\n",student1.stu_id,student1.name,student1.score[0],student1.score[1],student1.score[2]);
printf("学号:%d\n姓名:%s\n,成绩:%d,%d,%d\n",student2.stu_id,student2.name,student2.score[0],student2.score[1],student2.score[2]);
return 0;
}