Code:
void getinfoStudent()
{
system("cls");
int studentnum, i, j = 0;
printf("Please type the student number to look at the student's information: ");
scanf("%d",&studentnum);
FILE *fp;
fp = fopen("studentinfo.txt","r");
if (fp == NULL) {
printf("I couldn't open results.dat for printing.\n");
exit(0);
}
for (i = 0; i<MAX; i++)
{
if(studentnum == student[i].studentnumber)
{
printf("First Name Last Name A1 A2 A3 A4 A5 L1 L2 L3 L4 L5 Midterm Final\n");
printf("%s %s %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
student[i].firstname,student[i].lastname,student[i].studentnumber,student[i].markAssignment[0],
student[i].markAssignment[1],student[i].markAssignment[2],student[i].markAssignment[3],student[i].markAssignment[4],
student[i].markLab[0],student[i].markLab[1],student[i].markLab[2],student[i].markLab[3],student[i].markLab[4],
student[i].markMidterm, student[i].markFinal);
fclose(fp);
break;
j = 1;
}
}
if (j == 0)
{
printf("Invalid student number. Please type it again.\n");
getch();
system("cls");
getinfoStudent();
}
}
I've posted wrong code in my previous thread, so I decided to make another thread.
I'm trying to compare the scanned student number with the student number in the file. If the scanned student number matches to the student number in the file, the program prints the specific information of the student with that number. Otherwise, it prints invalid and goes back to scanning part.
I've tried to use for loop to find if there is any numbers which match up to the number in the file. However, seems like it's not working properly.
Could anyone help me with this problem?
Thank you!!