We have a project for our CS class thats purpose is to read 3 different files, compare them, and list exam scores and user names in a new file

The files are to be as follows:

class.txt - This is the roster of the course. The first column is the identification number of the student followed by the name of the student.

webCT.txt - This is the file with the necessary information to upload scores to WebCT. The first column is the identification number of the student and the second is the university ITaP login.

exam.txt - This file contains the student identification number and the score earned on the exam.

uploadExam.txt - The file you will create, this file will have the the score and university ITaP login for each student separated by a comma and a space (this is known as a comma delimited file). If a student in the class.txt file does not have a score in exam.txt then the university ITaP login and a score of zero should be listed in this file.

badID.txt - In this file you will place all records in exam.txt that DO NOT have a matching student identification number in the class.txt file. Data placed in this file are a result of an incorrectly coded student identification number.

The files are also formatted as follows:

In class.txt:

12345 Jackson, Keith
11111 Gibson, Robert G
22222 Sanders, Ryan
33333 Anderson, Jennifer A
44444 Martinez, Mary

In webCT.txt:

12345 jacksonk
11111 gibsong
44444 martinez33
22222 sandersr
33333 janders

In exam.txt:

11111 75 Gibson, Bob G
22222 88 Sanders, R
33333 90 Anderson, Jenny
12344 77 Jackson, Keith

In uploadExam.txt:

Exam1Score, User Id
0, jacksonk
75, gibsong
0, martinez33
88, sandersr
90, janders

In badID.txt:

12344 77 Jackson, Keith

so far we have gotten our program to load the first two files, but we are stuck on how to load the exam.txt file. We can only use strings for this project and it will eventually need to be able to accept any number of inputs. Here is our code:

Code:
#include <stdio.h>

int main ()
{
  FILE *fpClass;
  FILE *fpwebCT;
  FILE *fpexam;
  int id1;
  int id2[5];
  int counter;
  int counter2;
  char character[35];
  char names[6];
  char names2[6];
  int id3;
  int id4[5];
  char login[35];
  int counter3;
  int i;
  int score;
  int id5;
  int id6[5];
  int scores[6];

//********class.txt********
  
  fpClass = fopen("class.txt", "r");

for(counter=1; counter <= 5; counter++)
   {
   fscanf(fpClass, "%d%d%d%d%d", &id1);
   //printf("%d\n", id1);
   id2[counter] = id1;
//printf("\n\n%d\n\n", id2[counter]);

   fgets(character, 35, fpClass);
//   printf("%s\n", character);
   names[counter] = character;
//printf("\n\n%s\n\n", names[counter]);
   }

fclose(fpClass);

//********webCT*******

fpwebCT = fopen("webCT.txt", "r");

for(counter2 = 1; counter2 <= 5; counter2++)
   {
	   fscanf(fpwebCT, "%d%d%d%d%d", &id3);
	   //printf("%d\n", id3);
   	   id4[counter2] = id3;
	   fgets(login, 35, fpwebCT);
	   //printf("%s\n", login);
	   names2[counter2] = login;
	   for (counter3=1; counter3 <=5; counter3++)
	   {
		   if (id4[counter2] == id2[counter3])
		   {
			   printf("%d\t", id4[counter2]);
			   printf("%s\n", login);
		   }
	   }
   }
   
	  fclose(fpwebCT);

//*******exam*******
  fpexam = fopen("exam.txt", "r");
    counter2 = 0;
    for(i = 1; i <= 4; i++)
    {
	   fscanf(fpexam, "%d%d%d%d%d", &id5);

	   printf("%d\n", id5);
   	   id6[i] = id5;
	   fscanf(fpexam, "%d%d", &score);
	   printf("%d\n", score);
	   //scores[i] = score;
	   //printf("%d", scores[i]);
	   for (counter2=1; counter2 <=5; counter2++)
	   {
		   if (id4[i] == id6[counter2])
		   {
			   printf("%d\t", score);
			   printf("%d\n", login);
		   }
	   }
	   
   }


fclose(fpexam);
   return 0;
}
Currently we are recieving a segmentation fault when we run the program for the exam.txt file. Any help that anyone could give us pertaining to this problem, or any other help in writing this code would be great.