Hi I am having some trouble reading my file into an array. I have a file that has multiple lines of chars the first line is a test key the subsequent lines are the student answers...how can I read the first line into an array and the other lines into another array to compare the two to get an output that gives
• the number of exams and the score (number of correct questions) for each exam.
• for each of the eleven (0-10) possible scores, the number of students who earned that score
use an integer array of "accumulators" (sums) for this -- array element 3, for example, contains the number of exams with a score of 3.
I know how to read the file into one array, but I don't know how to read specific lines from a file into an array. Thanks
Well, one thing you need is to know when you hit the end-of-line, given by '\n'. Another is when you hit end-of-file, which is defined in stdio.h as EOF .
If you want to write your own function to read the chars to an array, you could use fgetc(), and loop until it returns '\n' for each line. If you are certain you're only ever going to have tests of a certain number of questions, you could use fgets(), or fread().
And then you wanted to store the results in a sort of histogram, which shouldn't be hard, especially if you know how many questions there are before hand. Otherwise, you could scan just the first line until you reach the newline character, or prompt the user, to find how many questions there are.