I have to create an array from an input file and then extract the calculated information from the array back to an output file. I understand how to bring in an input file but I am unsure how to put this information into an array. Here is the assignment incase that helps explain what i am trying to ask.

1. Read an input text files called inputFile.txt. You can generate this file using Notepad. The file contains 10 columns and many lines. Each line is a student’s quiz scores (a score is a two or one digit integer). The first column is the names of students. Different words in a name are connected by underscore. E.g., John_Stevens. Each of other columns is a quiz score. There may be multiple spaces or tabs between columns. The first line describes the title in each column (Name Quiz_1 Quiz_2 …. Quiz_9). The rest lines are the student scores. The last line only contains one word END. It is assumed that number of students is no more than 100

2. Write a routine that accepts an array of numbers as input and returns high, low, and average of the array.

3. Calculate the high, low, and average of all quizzes.

4. Print the result in a file outputFile.txt in a format similar to the input file but has three rows representing high, low, and average of each quiz

what you need is a 2-dimensional array of integers with 10 columns and a dynamically expandable number of rows to hold the scores. Here is some more information about this:

After you understand multiple-dimensional arrays and how to allocate them then you will be ready to read the data into those arrays.

Actually, you don't need to understand allocation at all. The instructions say:

The file contains 10 columns and many lines.
...
It is assumed that number of students is no more than 100

So all you need is an array of 100 lines of 10 columns.

If you know structures, you can create a structure that contains
-- Student's Name
-- Array of 9 scores
Then make an array of 100 of the structures.

If not, make 1 array of 100 character strings of a maximum size for the names. Something like char names[100][21]; for 100 students with a maximum of 20 characters per name.
Then make another array for the scores, like int scores[100][9]; Since you know the exact format of each line, in a while loop, use fgets() to read an entire line. Then use sscanf() to break the line into the structure or the arrays.

commented: Nicely taught. +3

Use data structure & linked list . it can be grown dynamically

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.