Hi, I am trying to understand the Standard C function "getchar()".
I am using CodeBlocks 8.02 in Windows XP.
Please compile this code in your compiler and note how it behaves:
#include<stdio.h>
int main()
{
int i=getchar();
while(i!=9)
{
printf("%d",i);
i=getchar();
}
printf("%d",i);
return 0;
}
When I insert Tab, it prints "9" and terminates.
But when anyother character is inserted it prints ascii value of that character
+ ascii value of '\n' (10)!
e.g. If I insert "a", it prints "9710"!
Why it prints "10" too?
when I insert more than one characters, it prints ascii values of all that characters + ascii value of '\n' (10)!
e.g. If I insert "a b", it prints "97329810"!
Why? Can anyone please explain how this happens?