***I have a feeling that there might be something wrong with my function
int fgetAnswers(int*pos, char res[], FILE*inp);
I am able to compile, but the problem is that wherever the black screen appears, a box would pop out saying that the program has stopped working. Can any of you guys please have a look and rectify it for me?Do you have a suitable function which I could use other than that? And if there seems to be an error in my coding, please help me to correct it. I just can't seem to get this worked out. Please help.. After compiling, it should appear something like this..
5 dbbac
111 dabac
102 dcbdc
251 dbbac

Exam Report

Question 1 2 3 4 5
Answer d b b a c

ID Score(%)
111 80
102 60
251 100

Question 1 2 3 4 5
Missed by 0 2 0 1 0


#define  input "examdat.txt"
#define  output  "report.txt"
int fgetAnswers(int*pos, char res[], FILE*inp);
int main()
 inp = fopen(input,"r");
 outp = fopen(output,"w");
 int numberofquestion;
 int numberofstudent;
 char studentanswer[30][30+1];
 char ans[30];
 int correct;
 int ID[30];
 int studentID[30];
 int wrong[30];
 int score[30];
 int status = fgetAnswers(&numberofstudent, ans, inp);
 for(int m=1;m<numberofstudent;m++)


 printf("ID       score(%%)\n");

 while(EOF != status)
   status = fgetAnswers(&numberofstudent,ans, inp);
   double answer=0.0;
   for(int i=1;i<=numberofstudent;i++)
 if(ans[i] == ans[i])

   fprintf(outp,"%d %d\n",ID,(correct*100)/numberofquestion);
   printf("%d %d\n",ID,(correct*100)/numberofquestion);

  printf("\n number:");
  for(int j=1;j<numberofstudent;j++)
  printf("\n missed by:");
  for(int j=1;j<numberofstudent;j++)

  return 0;

int fgetAnswers(int*pos, char res[],FILE*inp)
    fscanf(inp, "%d", pos);
    char b;
    int i=0;
    while('\n' != b)
 int status = fscanf(inp,"%c",&b);
    return status;   

Edited 5 Years Ago by Narue: added code tags

First of all, use code tags whenever you post any code.See that CODE thingy, click that and paste your well formatted code in between.

There's no use of this #include<conio.h>in your code and why this char studentanswer[30][30+1]; why not just declare it like this

char studentanswer[30][31];

Since you're opening the file 'examdat.txt' for reading, make sure that it is in the same directory as your program is or use the full path.

int status = fgetAnswers(&numberofstudent, ans, inp); You are passing arguments without assigning any values to them.

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.