//just go thru the simple prog
#include
#include
int main()
{
char str[5];
int i;
for(i=0;i<5;i++)
{
printf("\n enter the character :");
scanf("%c",str+i);
}
printf("\n %s\n ", str);
return 0;
}
predict what is the output
if u think output is
"
enter the character :a
enter the character :b
enter the character :c
enter the character :d
enter the character :e
abcde
"
then u r wrong..
output is
enter the character :a
enter the character :
enter the character :b
enter the character :
enter the character :c
a
b
c
"
this is the original output..
can someone please help and elaborate..
The newline left in the input buffer from the first scanf call is still there and gets read by the second. One of the easiest ways to deal with this might be to just put a space in front of the %c specifier OR you can flush the input stream using fflush(stdin) just before scanf();
dont htink..
222 much..:)
thinking is such a waste of tym…
evn i got the same o/p…:)