一个记录学生成绩并保存在文件中的小程序,不知道哪里错了,编译没错,但不能输入,求解
#include<stdio.h>#include<stdlib.h>
#define M 1000
struct subjects
{
float *Math;
float *English;
float *Chinese;
};
struct stu
{
char *name;//名字
long *num;//学号
struct subjects score;//输入成绩
}stu[M],*p;
int main()
{
FILE* fp;
int i,choose,n=0;
if ((fopen_s(&fp,"list.txt", "wb+"))!=0)
{
printf("can't creat file! return...\n");
exit(0);
}
for (i = 0; i < M; i++)
{
printf("输入名字:");
scanf_s("%s", &p->name);
printf("输入学号:");
scanf_s("%d", &p->num);
printf("输入成绩:\n");
printf(" 数学:");
scanf_s("%f", &p->score.Math);
printf(" 英语:");
scanf_s("%f", &p->score.English);
printf(" 语文:");
scanf_s("%f", &p->score.Chinese);
n = i;
printf("按任意键继续,若输入完成按0退出\n");
scanf_s("%d", &choose);
if (choose == 0)
exit(0);
}
for (i = 0; i < n; i++, p++)
{
fprintf_s(fp, "%2s%2d%2f%2f%2f", p->name, p->num, p->score.Math, p->score.English, p->score.Chinese);
printf("\n");
}
fclose(fp);
return 0;
}