I'm struggling to overcome this error. My function is supposed to read data from a file into an array of structures.
Data file example:
1234 52 70 75
2134 90 76 90
3124 90 95 98
Structure definition (average is calculated later):
struct Student
{
int id, testOne, testTwo, testThree;
float average;
};
typedef Student student_array[SIZE];
Function:
void SetArrays (student_array * s)
{
student_array *ptr = s;
fstream fin ("lab5_data.txt");
if (fin.is_open())
{
fin >> ptr->id;
}
}
I can't figure out how to use pointer arithmetic to iterate through the function, this is the errore I get:
[Error] request for member 'id' in '* ptr', which is of non-class type 'student_array {aka Student [20]}'
SOLUTION:
I was able to work through the problem with the advice given here, as well as reddit. Here is my solution, thanks all.
void SetArrays (Student * ptr)
{
//TODO: Function Spec:
fstream fin("lab5_data.txt");
cout << "Data read in:" << endl;
if (fin.is_open())
{
for (int i = 0 ; i < SIZE ; ptr++, i++)
{
fin >> ptr->id;
fin >> ptr->testOne;
fin >> ptr->testTwo;
fin>> ptr->testThree;