1. 14 arrays? That's madness. You should get familiar with the concept of structures and start handling 1 array.
2. Post your current code and we'll build on it.
1. Your counter variable 'i' needs to start in zero, not one. Remember that arrays start at index zero, not index one.
2. Your code should check if the maximum number of records is reached before the end of file is reached:
while (!indata.eof() && i < max)
If you don't do this check, your program will crash trying to read more than 'max' lines.
3. Streams have this method called good(). It returns a boolean value equal to true if the stream is good to go. It will return false if extraction of a value fails. You should check the value of good() whenever you extract data.
Right, you need to keep track of how many rows you read using another variable:
1 2 3 4 5 6 7
int numRecords = 0;
int i = 0;
while (!indata.eof() && i < max)
{
...
numRecords++
}
Yes, your 'i' variable would have worked, but because of its generic name one tends to reuse those, meaning I would prefer a variable with a specific name for the specific purpose.
With this new variable you can now write to output streams:
Did you verify the good() state of the input stream? I don't see it in your code, so my guess is No. Also remember to skip the first line of the input if the input file contains column headers.
You can also ensure that data is written to the arrays properly by first initializing the memory (only works on arrays of primitive types):
memset(g, 0, sizeof(g)); //Etc. One of these per array. Not on array of strings.
Well, the thing is rather simple: good() will return true if data extraction was successful. For example, good() will return false if you try to extract a name into a variable of type int or double. So inside your while() loop you should check for good() after you extract the data. If good() returns false, you should alert the user of the application that the data is most likely corrupt and exit.