Question: 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;

```

Answer: 
`ptr` is a pointer to an array.

`*ptr` dereferences the pointer, so the result is an array.

`(*ptr)[i]` is an element of that array, which is a `Student` struct.

`(*ptr)[i].id` is a member of that struct.

Your code is wrong because it tries to dereference `ptr` with `->` (fine so far, `ptr` is a pointer so dereferencing is a valid operation), but then tries to immediately get an `id` member, but it's still looking at the whole array. The compiler message roughly means "you told me to get the `id` field of an array, which makes no sense because arrays only have indices, not named fields".

If you want to use pointer arithmetic, it's easier to get rid of that `typedef` and pointer-to-array business:

```
void SetArrays (Student *ptr)
{
    fstream fin ("lab5_data.txt");

    if (fin.is_open())
    {
        while (fin >> ptr->id)
        {
            ptr++;  // advance to the next array element
        }
    }
}

```

In this version the function takes a pointer to the first element (and uses `++` to step through the array), not a pointer to the whole array.
student\_array is an array.

You need to read into a given element of that array

like this

```
fin >> ptr[0]->id;

```

you probably want a loop and use the loop index as the array index