There are several problems. I am assuming that an athlete has 5 grades. If not, there are more things wrong.
You have to allocate the memory to the structure. I preferred to opt for dynamic allocation with malloc()
. And don’t need to spend with &
, he’s already a pointer.
Access to the index shall be made on notas
and not on the athlete’s object, in case it was used l
(bad name of variable). Unless there are 5 athletes with a note each (it would be strange to use a structure for this).
And access to the member should be done with the operator ->
since it is a reference.
#include <stdio.h>
#include <stdlib.h>
typedef struct Atleta {
float notas[5];
} atleta;
void receberNotas(atleta* l) {
for (int i = 0; i < 5; i++) {
printf("Digite %d nota: ", (i + 1));
scanf("%f", &l->notas[i]);
}
}
void mostrarNotas(atleta *l) {
for (int i = 0; i < 5; i++) printf("\n%.2f", l->notas[i]);
}
int main() {
atleta *a = malloc(sizeof(atleta));
receberNotas(a);
mostrarNotas(a);
}
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
See the Actual difference between point operator (.) and arrow operator (->) in C?
I couldn’t remember some concepts, I went for a while without studying.
– user56270