#include <stdio.h>
#include <stdlib.h>
#define NAME_MAX 10
#define NUMBER_MAX 10
#define STUDENTS_MAX 5
#define CLEAR_ENTER(array) for(int idx=0;array[idx]!='\0';idx++)\
if(array[idx]=='\n')\
array[idx]='\0';
typedef unsigned int Uint32;
typedef struct stu
{
char name[NAME_MAX];
char stu_number[NUMBER_MAX];
Uint32 chinese;
Uint32 math;
Uint32 english;
} stu;
int main(void)
{
stu students[STUDENTS_MAX];
int idx=0;
printf("输入5个学生的信息\n");
for(idx=0;idx<STUDENTS_MAX;idx++)
{
printf("name:");
fgets(students[idx].name,NAME_MAX,stdin);
printf("number:");
//fgets(students[idx].stu_number,NUMBER_MAX,stdin);
fgets(students[idx].stu_number,NUMBER_MAX,stdin);
printf("三项分数(语文,数学,英语):");
scanf("%d%d%d",&students[idx].chinese,&students[idx].math,&students[idx].english);
getchar();
}
FILE * fp = fopen("stu.txt","w+");
if(!fp)
return -1;
for(idx=0;idx<STUDENTS_MAX;idx++)
{
printf("name:%s\nnumber:%s\nchinese:%d\nmath:%d\nenglish:%d\n",students[idx].name,
students[idx].stu_number,
students[idx].chinese,
students[idx].math,
students[idx].english);
fprintf(fp,"name:%s\nnumber:%s\nchinese:%d\nmath:%d\nenglish:%d\n",students[idx].name,
students[idx].stu_number,
students[idx].chinese,
students[idx].math,
students[idx].english);
}
system("pause");
return 0;
}
简单的写了一个,没有调试过。编译通过,Mingw3.4.7.