A user can enter various different amounts of numbers (as long as they don't enter over 5000 numbers). However, when the user presses CTRL+D, the program should stop requesting user input. I've done this so far. However, I have to press CTRL+D twice before it stops. Could someone help me to fix it?
int input_array[MAX_NUMBERS] = {0};
scanf("%d", &input_array[0]);
int eof_detector = getchar();
int i = 0;
while ((i < 5000) && (eof_detector != EOF)) {
i++;
scanf("%d", &input_array[i]);
eof_detector = getchar();
}