I need to read all integers until the EOF. I'm trying this code and the problem is that the program doesn't detect the EOF and keeps running. What I need is to receive all the data and proceed to the next line of code automatically (the code works with pressing Ctrl-D after the input).
int x, sum = 0;
while (scanf("%d", &x) == 1) {
sum += x;
}
if (feof(stdin)) {
printf ( "SUM: %d\n", sum );
} else {
printf("ERROR\n");
}
return 0;