The cheapest version of what you want is something like this:
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int id;
int size; // size of grades array
int *grades;
} Student;
int main() {
Student s;
s.size = 0;
s.grades = NULL;
int n;
while (scanf("%d", &n) == 1) { // ctrl-d (ctrl-z on windows) to quit
s.grades = realloc(s.grades, ++s.size * sizeof(*s.grades));
s.grades[s.size-1] = n;
}
for (int i = 0; i < s.size; i++)
printf("%d\n", s.grades[i]);
return 0;
}
Problems:
* no error checking: in particular if realloc fails you lose the pointer to previously allocated memory.
* inefficient: it's more efficient to increase the array size by doubling (or increasing by at least 50%) when you are out of space. But then you need to keep track of the "capacity" (total number of elements allocated) as well as the "size" (number of elements in use).