Replace the feof loop with conversion-driven reading

Repair the fragment to read numbers.txt, a text file intended to contain at most 100 integers in -1000..1000 separated by whitespace. All numeric tokens presented to %d are representable as int; nonnumeric tokens must be rejected. Print count=k sum=s on success, open error if opening fails, or invalid data or I/O error for a bad token, out-of-range value, excess count, read error or close error. Explain the stale-value bug on a normal end-of-file and why a nonnumeric token can leave the broken loop stuck. Empty files are valid. Do not execute the broken fragment.

FILE *in = fopen("numbers.txt", "r");
int x = 0, sum = 0;
while (!feof(in)) {
    fscanf(in, "%d", &x);
    sum += x;
}
printf("%d\n", sum);

