> Why the output of the following program is like this??

Why the output of the following program is like this??

Posted at: 2014-12-18 
Because, what you don't realize is that you are entering each letter one per line and that doing so also adds '\n' as a character. Your program doesn't show you what character it got with scanf(). If it did, I think you'd see the extra characters involved.

You are entering "a\ne\nr\nx\n" and the scanf() call fetches a, \n, e, \n, r, \n, x, and never gets a chance to fetch the last character, \n, because the loop exits.

program:

#include

int main()

{

char ch;

printf("Enter keys, x to stop\n");

do

{

printf(":");

scanf("%c",&ch);

}while(ch!='x');

printf("End");

return 0;

}

i think it will give the output like this

:a

: e

:r

: x

END

but it gives

output:

:a

:: e

::r

:: x

END

why is the : is printed twice

please explain