Le us consider the following piece of code in C:
#include <stdio.h>
#define SCORES 3
typedef struct struct_student{
char name[16];
float scores[SCORES];
float average;
} STUDENT;
int main(){
STUDENT student, *p;
int i;
p = &student;
printf("Name:\n");
gets((*p).name);
for(i=0;i<SCORES;i++){
printf("score:\n");
scanf("%f", &(*p).scores[i] );
(*p).average = (*p).average + (*p).scores[i];
}
(*p).average = (*p).average/SCORES ;
printf("%s has average %f\n",student.name, student.average);
return 0;
}
It is working well. But I think that there is another way to specify the scanf:
scanf("%f", &(*p).scores[i] );
I mean. This seems to be overcomplicated. I would like to know if there is another way to do this using the "dot notation". That is, I know that there is the "arrow notation" that is much easier. But I think that even using the "dot notation" there is some better way to do this. Notice that I'm trying to understand how to use the "dot notation", so I'm not interested in solutions with the "arrow notation".