#include<stdio.h>
#define shuru "examdat.txt"
#define shuchu "report.txt"
#define q_num 5
void score(char c[],int *x,int missnum[]);
char ans[q_num];
int main()
{
int num,
i,
n,
m;
char ans1[q_num];
char name[]={"exam report"};
char name1[]={"Question"};
char name2[]={"Answer"};
int Missnum[5]={0};
FILE *inp;
FILE *outp;
inp=fopen(shuru,"r");
outp=fopen(shuchu,"w");
fscanf(inp,"%d %c%c%c%c%c",&num,&ans[0],&ans[1],
&ans[2],&ans[3],&ans[4]);
fprintf(outp,"%20s\n",name);
fprintf(outp,"%s",name1);
for(i=1;i<=q_num;i++){
fprintf(outp,"%6d",i);
}
fprintf(outp,"\n%s
",name2);
for(i=0;i<q_num;i++){
fprintf(outp,"%6c",ans[i]);
}
fprintf(outp,"\n");
fprintf(outp," ID
SCORE(%)\n");
while(!feof(inp)){
int n=0;
fscanf(inp,"%d %c%c%c%c%c",&num,&ans1[0],&ans1[1],
&ans1[2],&ans1[3],&ans1[4]);
score(ans1,&n,Missnum);
m=(n*100)/5;
fprintf(outp,"%3d%10d\n",num,m);
}
fprintf(outp,"\nQuestion");
for(i=1;i<=q_num;i++){
fprintf(outp,"%6d",i);
}
fprintf(outp,"\nmissed by");
for(i=0;i<q_num;i++){
fprintf(outp,"%6d",Missnum[i]);
}
}
extern char ans[q_num];
void score(char c[],int *x,int missnum[])
{
int i;
for(i=0;i<q_num;i++){
if(c[i]==ans[i])
{
*x=*x+1;
missnum[i]=missnum[i]+0;}
else missnum[i]=missnum[i]+1;
}
}
我的代码生成的文件为什么多出了251 那一行