bash-3.2$ cat problem.c
#include <stdio.h>
#include <stdlib.h>

int main () {

char str[2];
str[0]=(char)0;
str[1]=(char)0;

scanf ("%1s%*[\n]", str);

printf ("str = %u %u\n", str[0], str[1]);

return EXIT_SUCCESS;
}
bash-3.2$ gcc -Wall problem.c -o problem.exe
bash-3.2$ ./problem.exe
a
a
str = 97 0
bash-3.2$

  Why scanf did not return when I pressed enter the first time?

bash-3.2$ ./problem.exe
b
b
str = 98 0
bash-3.2$ ./problem.exe
a
b
str = 97 0
bash-3.2$

  I do not understand.


Reply via email to