
please wait
scanf()
routine catches the '\n'
character. That's why the default statement is executed after you hit enter. but according to the study meterial you provided ref to http://www.cplusplus.com/reference/clibrary/cstdio/scanf/ it says " ..the function will read and ignore any whitespace characters (this includes blank spaces and the newline and tab characters) which are encountered before the next non-whitespace character. This includes any quantity of whitespace characters, or none.." |
scanf()
function, not the line you enter at runtime. The first argument of scanf()
in your code is "%c"
. #include <conio.h>
scanf()
line by a = getch();
getch()
retrieves a single key stroke. I hope this works for you.
Firstly, you are absolutely right, that the scanf() routine catches the '\n' character. That's why the default statement is executed after you hit enter. |
|
|
|
|
scanf
grabs BOTH entered characters at ONCE like before but now it tries to apply both "entered letter" and "\n" to the variable A (char A) . but since A was entered first. A goes in first.