This is my assignment Question for a first semester C programming course.
You have been hired under a student working scheme program. Your first task is to write a C program to assist in one of the professors in the faculty to grade the final exam of his/her students. The exam consists of 20 multiple-choice questions. Each question has one of four possible answers: A, B, C, or D. The program will read in the students’ answers and the correct answers from files and prints out the result onto the screen and also the file output. There are at least 15 students in class.
What I'm thinking to do is to read the file of the students answers and store the values in an array using a function and the same thing with the correct answers file, then return both arrays to the main function and send them to another function to compare the answers. However I am having trouble in returning the string arrays to the main function.
This is my code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
//Modules
char** readstudent()
{
FILE*s_ans;
static char arrs[20][20];
int i,j;
s_ans=fopen("trial2.txt","r");
if (s_ans == NULL)//check if file can be opened
{
printf("error student");
}
while(!feof(s_ans))
{
for(j=0;j<20;j++)
{
fscanf(s_ans,"%s",arrs[j]);
}
}
printf("ReadStudent\n");
for(i=0;i<20;i++)
{
printf("%d\t %s\n",i+1,arrs[i]);
}
return arrs;
}
char** readcorrect()
{
FILE*c_ans;
static char arrc[20][20];
int x,i;;
c_ans=fopen("CorrectAnswers.txt","r");
if (c_ans == NULL)//check if file can be opened
{
printf("error correct");
}
while(!feof(c_ans))
{
for(x=0;x<20;x++)
{
fscanf(c_ans,"%s",arrc[x]);
}
}
printf("ReadCorrect\n");
for(i=0;i<20;i++)
{
printf("%d\t %s\n",i+1,arrc[i]);
}
return arrc;
}
//Main
int main()
{
int i,j,n,x;
char **as_ans;
char **ac_ans;
as_ans=readstudent();
ac_ans=readcorrect();
printf("Main");
for(i=0;i<20;i++)
{
printf("%s",as_ans[i]);
}
return 0;
}
}
and I'm getting "[Warning] return from incompatible pointer type" twice after compiling it.
Anyone could help me to successfully return the arrays back to the main function please? Note that this is my first time dealing with C Thank you!