You're probably going out of bounds when it comes to reading in the file and displaying those values within the for loop(this tends to create garbage values if not properly implemented.). From your output, it seems that john is getting Mary's grades. Try subtracting 1 from MAX(the one in the for loop or i<MAX-1).