I read few questions on Stack Overflow but everyone here is explaining that has already been explained in K&R. I want to ask when the below program runs. Then if I input my name in the console then it get printed in the next line. Firstly this function's name is getchar
why it doesn't take just one character 'a' or any other? I get correct output irrespective of how long my input is.
I wrote 'adfsajfsjssadfsa.......up to to 100 characters and putchar copied it exactly'. Also book is using int
. I know int
can hold data up to 4 bytes much bigger than char
but what's the use of providing data types in C if we can use any of them.
Why does putchar
print it to next line? Is it built this way to always print the output in next line? I wrote adfsajfsjssadfsa.......upto to 100 characters and putchar copied it exactly
when will a situation come that I would get error and integer c
won't be able to hold that big data. How many characters?
#include <stdio.h>
int main()
{
int c;
c=getchar();
while(c!=EOF){
putchar(c);
c=getchar();
}
}