#include <stdio.h>
int main(void) {
int n,m=5;
char c;
while(m>0)
{
m--;
scanf("%d",&n);
if(n==42)
break;
printf("%d",n);
fflush(stdin);
scanf("%c",&c);
puts(&c);
}
return 0;
}
Although I know that when a enter is pressed after entering a number at first scanf
, it(enter) is taken as input by the second scanf
, but my doubt is that, when I give 5ttttt
as input , the output is
5t
5t
5t
5t
5t
as there is no integer in input buffer, why it is not asking for input of integer|
Second question is, even if we follow the above behavior, then on giving input of 5t
and then pressing enter should take two characters as buffer ('t' and 'enter') but only t is taken in buffer and the output is
5t
but I expected the output
5t
5
as 'enter' would be taken in buffer and it will not ask for integer input in the second iteration of loop.