Hi,
I'm working an a project that must take a text file (provided to us, in.txt) that has the scores of students from different sections on different labs. You can view the assignment page at: http://www.cs.wmich.edu/~nelson/CS111FALL04/lab06/index.htm.
The problem I'm having is that I can't think of how to make a function that will read the file and put it into an array (no function in this program is supposed to be more than 24 lines so there's no way it can go into the main funciton, I was planning on making a readFile function to do this work).
Can you pass a file to a funciton as a paramater (I got an error, I didn't think it was possible, just wanted to try)? Should I read the file in main and somehow pass it to the function in some way? I'm also quite lost as far as I should go about getting the data from the text file stored correctly into the array. This is an example of how the info in the data file is stored:
The input file:
Name: “in.txt you must use the name in.txt
First line 2 integers:
The number of sections in the class <= 10
The number of lab assignments in the class, NumLabs <= 10
For Each Section
First Line, 1 Integer: N The number of students in the section <= 50
For each Student
Student Id L1 L2 … LNumLabs
Student Id: 4 digit integer
Labs scores: Integers 0 to 100
Example: A small class with 3 sections and 4 labs.
The first section has 4 students, the second 5 and the third 4
3 4
4
8591 87 60 82 64
1881 95 63 75 94
6758 71 56 72 63
7541 65 95 84 87
5
3690 88 86 99 68
3515 78 60 98 53
1534 91 95 65 81
2459 86 69 79 50
7047 70 61 63 71
4
6204 89 98 56 69
6437 92 67 95 87
2012 67 97 66 54
8147 90 50 63 100
I tried setting up some for loops in a test program to read info from the input file into an array (not included into my actual program because as stated above I can't figure out how to implement it into my actual program) but go no where. Could someone help me figure out how to go about this? I would be very grateful to any help.
thanks again for everything,
-Scott