Hey there.
Well, you implemented the reading from the file, but you did not STORE the data anywhere to allow you to do what you want.
My suggestion would be to implement a structure, like this.
1 2 3 4 5 6
|
struct patient
{
int ID;
int NumberOfReadings;
int Reading[10];
};
|
Then, you make a array of patients:
patient Patients[50];
And then you read the file and fill Patients[] with the goodies:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
int patientCount = 0;
ifstream reader ("data.txt"); //Open The Data File To Be Read From
for (i = 0; i<50; i++)
{
if ( ! (reader >> Patient[i].ID && reader >> Patient[i].NumberOfReadings ) ) //*same as your while
{
patientCount = i; //*if cant read, then the number of patients is the current i
break; //*if cant read, breaks the for loop
}
for (j=0; j<Patient[i].NumberOfReadings; j++)
{
reader >> Patient[i].Reading[j];
}
}
|
* I did not test this code, this is just to give you a idea of how to do what you want.
** This is not very elegant, since we are allocating a hard number of memory for patients and readings that may not be used, and may not be adequate for all situations. If your files have sometimes thousands of patients, maybe with hundreds of readings, its best to implement a dynamic method to allocate the resources, instead of arrays. But, I recommend getting this one done first.