haha sounds good any chance you would be able to tell me where i am going wrong with my code
Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
#include <string.h>
int main()
{
int score;
char answer[21];
char test[21];
char studentId[9];
FILE *grading;
grading = fopen("results.dat", "w");
if (grading == NULL)
{
printf("I couldn't open results.dat for writing.\n");
exit(0);
}
/* prints the students test results to the data file*/
fprintf(grading, "%s\n", "TTFTFTTTFTFTFFTTFTTF");
fprintf(grading, "%s %s\n", "ABC54102", "T FTFTFTTTFTTFTTF TF");
fprintf(grading, "%s %s\n", "DEF56278", "TTFTFTTTFTFTFFTTFTTF");
fprintf(grading, "%s %s\n", "ABC42366", "TTFTFTTTFTFTFFTTF ");
fprintf(grading, "%s %s\n", "ABC42586", "TTTTFTTT TFTFFFTF ");
fclose(grading);
grading = fopen("results.dat", "r");
if (grading == NULL)
{
printf("I couldn't open results.dat for writing.\n");
exit(0);
}
fscanf(grading,"%s", &answer);
printf("%s\n", answer);
{
fseek(grading, 2, SEEK_CUR);
while(!feof(grading))
{
fgets(studentId, 9, grading);
fscanf(grading,"%[^\n]", &test);
printf("%s", studentId);
printf("%s", test);
for(int i=0; i<21;i++)
{
score= 0;
if(test[i]=='T'&&answer[i]=='T')
{
score=score+1;
}
else if(test[i]==' '&&answer[i]==' ')
{
score=score+0;
}
else if(test[i]=='T'&&answer[i]=='F')
{
score=score-2;
}
}
printf("\tScore:%d", score);
}
}
fclose(grading);
return 0;
}