***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..
examdat.txt
5 dbbac
111 dabac
102 dcbdc
251 dbbac

report.txt
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

********************************

#include<stdio.h>
#include<conio.h>
#define  input "examdat.txt"
#define  output  "report.txt"
int fgetAnswers(int*pos, char res[], FILE*inp);
int main()
{
  FILE*inp,*outp;
 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++)
  wrong[m]=0;

 printf("%\n",ans);

 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])
 {
 correct++;
 }
 else
 {
 wrong[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("\t%d",j);
  printf("\n missed by:");
  for(int j=1;j<numberofstudent;j++)
    printf("\t%d",wrong[j]);

   fclose(inp);
   fclose(outp);
  return 0;
}


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

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.

How should I rectify it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.