代码要求:
1、假设已有题库、答案文件(solu.txt)和学生名单(stud.txt);
2、程序执行时首先自动随机生成每个学生的5道考试题目(不能重复且递增排序),保存到文件ques.txt中;
3、从控制台输入一个待查询的学生学号及相应答案列表(20102201 A,B,B,C,D),自动根据考试题目和答案文件计算学生的百分制成绩;
4、将该生的学号,姓名、成绩和详细信息打印到屏幕。格式如下:
2010813482 张三 80
11 A B
21 C C
32 D D
43 D D
51 C C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
int id_1 [95];
char name[10];
char name_1[95][10];
char answers[100];
int a,b,n,k,m,score,i,t,a1,a2,a3,a4,a5,a6,ID,id;
score=0;
int num[95][5];
char sol[5];
i=0;
FILE *file;
file=fopen("D:\stud.txt","r");
if (file==NULL){
printf("open error");
exit(1);
}
else{
while(fscanf(file,"%d %s",&id,name)!=EOF){
id_1[i]=id;
strcpy(name_1[i],name);
i++;
}
}
fclose(file);
scanf("%d",&ID);
printf("%d",ID);
for(a6=0;a6<5;a6++){
scanf("%c",sol[a6]);
}
for(a1=0;a1<95;a1++){
a=rand() % 100+1;
num[a1][0]=a;
n=1;
while (n<=5){
b=rand() % 100+1;
if(b!=a){
num[a1][n]=b;
n++;
}
}
for(t=0;t<4;t++){
for(k=t+1;k<5;k++){
if(num[a1][t]>num[a1][k]){
m=num[a1][t];
num[a1][t]=num[a1][k];
num[a1][k]=m;
}
}
}
}
file=fopen("D:\ques.txt","w");
if(file==NULL){
printf("open error");
exit(1);
}
else{
for(a2=0;a2<=95;a2++){
fprintf(file,"%s %d",name_1[a2],num[a2]);
}
}
fclose(file);
file=fopen("D:\\solu.txt","r");
if (file==NULL){
printf("open error");
exit(1);
}
else{
for (a4=1;a4<=100;a4++){
fscanf(file,"%c",answers[(a4-1)]);
}
}
for(a5=0;a5<=95;a5++){
if(ID==id_1[a5]){
for(a3=0;a3<5;a3++){
if(sol[a3]==answers[num[a5][a3]]){
score=score+20;
}
printf("%d %c %c\n",num[a5][a3],sol[a3],answers[num[a5][a3]]);
}
printf("\n%d %s %d\n",ID,name_1[a5],score);
}
}
fclose(file);
system("pause");
return 0;
}
这是代码,求大佬讲解,可以的话请指出错误
这个应该是中途有异常返回了,程序提前结束,尝试加断点调试一下
斜杠要转义
file=fopen("d:\stud.txt","r");
斜杠要转义,后面读写文件都一样
项目13为什么执行界面是项目14.exe
,感觉你执行的不是你的当前代码