#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
char nam[10];
int age;
}stu;
Input(struct student stu,FILE *fp)
{
printf("Please Input Your Name:");
scanf("%d",&stu.age);
printf("Please Input Your Age:");
gets(stu.nam);
if( ( fp = fopen("E:\studinf.txt", "w") ) == NULL)
{
printf("File open error!\n");
exit(0);
}
if(fwrite(&stu,40,1,fp)!=1)
{
printf("FILE write error!\n");
fclose(fp);
}
fclose(fp);
printf("\n");
}
int main()
{
printf("\t数学测验软件\t\n");
int size=sizeof(stu);
int c;
FILE *fp;
do{
printf("菜单:\t1:输入学生信息 2:开始测验 3:查看测验结果\n");
scanf("请输入你的选择:%d",&c);
switch(c){
case 1:
Input(stu,fp);
break;
case 2:
break;
case 3:
break;
case 0:
break;
}
}while(c!=0);
return 0;
}
scanf("请输入你的选择:%d",&c);这句要拆分为:
printf("请输入你的选择:);
scanf("%d",&c);
程序输出正常吗,你的问题是因为循环直接结束了吧
if( ( fp = fopen("E:\studinf.txt", "w") ) == NULL)
改成if( ( fp = fopen("E:\\studinf.txt", "w") ) == NULL)
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632