user-0 提问: 结构体写入文件

回复:
user: user-1
content: 希望对你有帮助：https://blog.csdn.net/it_xiangqiang/category_10581430.html 希望对你有帮助：https://blog.csdn.net/it_xiangqiang/category_10768339.html

user: user-2
content: VS2015 C++环境调试

user: user-0
content: 引用 1 楼 棉猴的回复:VC++6.0，我的最爱，但是还是上代码吧 #include<stdio.h> #include<stdlib.h> #include<time.h> #include<string.h> struct { 	int num; 	char name[10]; }body[100],t; void practice(); void menue(); void set(); void test(); void look(); void back(); void rank(); int main() { FILE*f1; 	if(f1=fopen("D:\\测验成绩.txt", "r")==NULL) 	{f1=fopen("D:\\测验成绩.txt","w");} 	else 	{f1=fopen("D:\\测验成绩.txt","r");} 	fclose(f1); 	printf("***第一次使用本程序先进行设置***\n"); 	menue(); return 0; } void practice() { 	FILE*fp; 	int a,b,c,d,m,i,g,h,e=0; 	char f; 	fp=fopen("D:\\设置文件.txt","r");     fscanf(fp,"%d,%d",&g,&h); 	fclose(fp); 	for(i=1;i<i+1;i++) 	{ 	printf("1.加法\n"); 	printf("2.减法\n"); 	printf("3.乘法\n"); 	printf("4.除法\n"); 	scanf("%d",&m); 	switch(m) 	{case 1: 	{  	srand((unsigned)time(NULL)); 	a=rand()%g+h; 	b=rand()%g+h; printf("%d+%d=\n",a,b); printf("请输入你的答案"); d=a+b; scanf("%d",&c); if(c==d) {printf("答案正确\n"); e=e+1;} else {printf("答案错误\n"); printf("正确结果为%d\n",d);}break;} 	case 2:{ 	srand((unsigned)time(NULL)); 	a=rand()%g+h; 	b=rand()%g+h; printf("%d-%d=\n",a,b); printf("请输入你的答案"); d=a-b; scanf("%d",&c); if(c==d) {printf("答案正确\n"); e=e+1;} else {printf("答案错误\n"); printf("正确结果为%d\n",d);}break;} 	case 3:{ 	srand((unsigned)time(NULL)); 	a=rand()%g+h; 	b=rand()%g+h; printf("%d*%d=\n",a,b); printf("请输入你的答案"); d=a*b; scanf("%d",&c); if(c==d) {printf("答案正确\n"); e=e+1;} else {printf("答案错误\n"); printf("正确结果为%d\n",d);}break;} 	case 4:{ 	srand((unsigned)time(NULL)); 	a=rand()%g+h; 	b=rand()%g+h; printf("%d/%d=\n",a,b); printf("请输入你的答案"); d=a/b; scanf("%d",&c); if(c==d) {printf("答案正确\n"); e=e+1;} else {printf("答案错误\n"); printf("正确结果为%d\n",d);}break;} 	} 	printf("总答题数为%d\n",i); 	printf("正确答题数为%d\n",e); 	printf("正确率为%.2f%%\n",e*1.0*100/i); 	printf("是否返回主菜单Y/N?\n"); 	getchar(); 	if(getchar()=='Y') 	{menue(); 	break;} 	}   }void menue() { 	int n; 	printf("算数练习\n\n"); 	printf("1.练习\n"); 	printf("2.测验\n"); 	printf("3.设置\n"); 	printf("4.查看测验成绩\n"); 	printf("5.排行榜\n"); 	printf("0.退出\n"); 	scanf("%d",&n); switch(n) 	{case 1:practice();break; case 2:test();break; case 3: set();break; case 4:look();break; case 5:rank();break; case 0: back();break; default: printf("输入错误"); } }void set() { 	int a,b,c,d,e,i; 	FILE*fp; fp=fopen("D:\\设置文件.txt","w+"); printf("请选择你计算的数字位数,支持1到3位\n"); scanf("%d",&i); switch(i) { case 1:a=9,b=1;break; case 2:a=90,b=10;break; case 3:a=900,b=100;break; default :printf("输入错误"); } 	printf("请输入测验模式的总题数\n"); 	scanf("%d",&c); 	printf("请输入测验模式的总分\n"); 	scanf("%d",&d); fprintf(fp,"%d,%d,%d,%d",a,b,c,d); fclose(fp); menue(); }void test() { 	FILE*fp,*f1; 	char name[10],ch; 	int a,b,c,d,i,g,h,m,f,k=0,s,w,p=0; 	if(f1=fopen("D:\\结构体数据.txt", "r")==NULL) 	{f1=fopen("D:\\结构体数据.txt","w"); 	fprintf(f1,"%d",p);} 	else 	{f1=fopen("D:\\结构体数据.txt","r"); 	fscanf(f1,"%d",&p); 	p=p+1; 	fclose(f1); 	f1=fopen("D:\\结构体数据.txt","w"); 	fprintf(f1,"%d",p);  	} 	fclose(f1); 	printf("请输入您的姓名\n"); 	scanf("%s",&name); 	fp=fopen("D:\\设置文件.txt","r");     fscanf(fp,"%d,%d,%d,%d",&g,&h,&f,&s); 	fclose(fp); 	fp=fopen("D:\\测试数据文件.txt","w+"); 	fprintf(fp,"题 目\t测验后的结果\t参考答案\n"); 	fclose(fp); 	for(i=0;i<f;i++) 	{ 	printf("1.加法\n"); 	printf("2.减法\n"); 	printf("3.乘法\n"); 	printf("4.除法\n"); 	scanf("%d",&m); 	switch(m) 	{case 1: 	{  	srand((unsigned)time(NULL)); 	a=rand()%g+h; 	b=rand()%g+h; printf("%d+%d=\n",a,b); printf("请输入你的答案"); d=a+b; scanf("%d",&c);// if(c==d) {k=k+1;} fp=fopen("D:\\测试数据文件.txt","a"); fprintf(fp,"%d+%d=\t  %d\t                %d\n",a,b,c,d); fclose(fp);break;} 	case 2: 		{srand((unsigned)time(NULL)); 	a=rand()%g+h; 	b=rand()%g+h; printf("%d-%d=\n",a,b); printf("请输入你的答案"); d=a-b; scanf("%d",&c);// if(c==d) {k=k+1;} fp=fopen("D:\\测试数据文件.txt","a"); fprintf(fp,"%d-%d=\t  %d\t                %d\n",a,b,c,d); fclose(fp);break;} 	case 3: 		{srand((unsigned)time(NULL)); 	a=rand()%g+h; 	b=rand()%g+h; printf("%d*%d=\n",a,b); printf("请输入你的答案"); d=a*b; scanf("%d",&c);// if(c==d) {k=k+1;} fp=fopen("D:\\测试数据文件.txt","a"); fprintf(fp,"%d*%d=\t  %d\t                %d\n",a,b,c,d); fclose(fp);break;} 	case 4: 		{srand((unsigned)time(NULL)); 	a=rand()%g+h; 	b=rand()%g+h; printf("%d/%d=\n",a,b); printf("请输入你的答案"); d=a/b; scanf("%d",&c);// if(c==d) {k=k+1;} fp=fopen("D:\\测试数据文件.txt","a"); fprintf(fp,"%d/%d=\t  %d\t                %d\n",a,b,c,d); fclose(fp);break;} 	}}// fp=fopen("D:\\测试数据文件.txt","a"); fprintf(fp,"答对题数%d\t答错题数%d\t您的分数为%.2f分\t姓名%s\n",k,(i-k),k*s*1.0/f,name); fclose(fp);     fp = fopen("D:\\测试数据文件.txt", "r");     f1 = fopen("D:\\测验成绩.txt", "a");     while((w = fgetc(fp)) != EOF)         fputc(w,f1);     fcloseall(); fp=fopen("D:\\测试数据文件.txt","r"); 	while( (ch=fgetc(fp)) != EOF ) 	{         putchar(ch);     } 	fclose(fp); 	body[p].num=(k*s/f); 	strcpy(body[p].name,name); 	fp=fopen("D:\\排行榜数据.txt","a");  	{fwrite(&body[p],sizeof(body),1,fp);} 	fclose(fp);   	menue();  }void look() { char ch; FILE*fp; fp=fopen("D:\\测验成绩.txt","r"); 	while( (ch=fgetc(fp)) != EOF ) 	{         putchar(ch);     } 	fclose(fp);      menue(); }void back() {exit(0); }void rank() {    }

user: user-2
content: VC++6.0，我的最爱，但是还是上代码吧