我写了这个程序的类。我有一个问题,显示什么在arry 我所得到的是符号而不是一个字符,即使我从教授提供的文件中填充字符。请帮我弄清楚这里有什么问题,我明天需要它填写Arry函数不存储字符和输出符号
// This program grades multiple choice exams1. Each exam consists of 20 questions.
//Each question has one of four possible answers: A, B, C, or D.
#include <stdio.h>
#include<stdlib.h>
#include <math.h>
const int maxsize = 20;
int fillArry (FILE *fi,char arry[],const int maxsize);
double gradeExam (char arry[], char studarry[],const int maxsize);
void desplayResults (double right);
int main()
{
char arry[maxsize];
char studarry[maxsize];
int num,num1,i,right;
FILE *fi,*sd;
fi = fopen ("CorrectAnswers.txt","r");
if (fi == NULL)
{
printf("Error opening input file.\n\n");
exit(1);
}
sd = fopen ("StudentAnswers.txt", "r");
if (sd == NULL)
{
printf("Error opening input file.\n\n");
exit(1);
}
num = fillArry (fi,arry,maxsize);
num1 = fillArry (sd,studarry,maxsize);
for (i=0;i<maxsize;i++)
{
printf("%c\n",arry);
}
for (i=0;i<maxsize;i++)
{
printf("%c\n",studarry);
}
right = gradeExam (arry, studarry ,maxsize);
printf("you got %i right\n", right);
desplayResults (right);
return 0;
}
int fillArry (FILE *fi,char arry[],const int maxsize)
{
int u = 0;
while((fscanf(fi,"%c",&arry)==1)&& u< maxsize)
{
u++;
}
return u;
}
double gradeExam (char arry[], char studarry[],const int maxsize)
{
int i, right=0, wrong=0;
for (i=1;i<=maxsize;i++)
{
if (arry[i]==studarry[i])
right++;
else
{
printf ("question number %i :%c is wrong, the correct answer is %c\n\n",i,studarry,arry);
wrong++;
}
}
printf("\nnumber of wrong answers: %i\n",wrong);
return right;
}
void desplayResults (double right)
{
double res;
res = (right/20)*100;
printf("You got %s %.2lf on the exam\n","%",res);
if (res<70)
printf ("You failed the exam\n");
else
printf ("You passed the exam\n");
}
为什么你不关闭打开的文件? – 2014-10-30 05:56:48
你能提供输入文件的例子吗? – Marcin 2014-10-30 05:58:15