Don't use fgetc. Just use fscanf to read the integers. You'll also have to use it to detect EOF. Something like:
Code:
int n;
while (fscanf(file, "%d", &n) == 1) {
    int a[n];
    for (int i = 0; i < n; ++i)
        fscanf(file, "%d", &a[i]);
    ...
}