I want this program show following.
Data input (Ctrl+Z to exit) : a
Data input (Ctrl+Z to exit) : b
Data input (Ctrl+Z to exit) : ^Z
sum : 2
But when I execute this code, Data input (Ctrl+Z to exit) :
printed a few times.
For example, when I input 'A', of course 'A enter' 2 characters,then 2 times of "Data input (Ctrl+Z to exit) : " printed.
int main(void)
{
int cnt = 0;
char input;
while (1) {
fputs("Data input (Ctrl+Z to exit) : ", stdout);
input = getchar();
if (input == EOF)
break;
fflush(stdin);
cnt++;
}
printf("sum : %d", cnt);
return 0;
}