In this line
scanf("%c", &a);
you are actually accepting% d from stdin (standard input), but while you typed a character from stdin, you also typed ENTER from the keyboard, which means that now you have two characters in stdin; the character itself and \ n. So, the program accepted the first character as the one you entered and the second character as \n .
You need to use
scanf("%c\n", &a);
to scan a new line (also by pressing the ENTER key).
Like rodrigo , you can also use them.
scanf(" %c", &a); or scanf("%c ", &a);
The way you think the second character is printed is wrong. It does print, but it's \ n, so your prompt may go to the next line.
Your code will work if you enter both characters without using ENTER.
shadyabhi@archlinux /tmp $ ./a.out qw q wshadyabhi@archlinux /tmp $
Note. When you used this, the only things that were in STDIN were q and w. So, the first is scanf ate q , and the second is w .
source share