Behavior of getchar() and putchar()
Hi, I have one or two question to said methods as a beginner in C.
Definition of getchar(): Each time it is called, getchar reads the next input character from a text stream and returns that as a value.
While putchar prints a character each time it is called.
Now I got the following programm:
Code:
#include <stdio.h>
int main() {
int c;
while ((c = getchar()) != EOF) {
putchar(c);
}
}
Why is the method getchar() able to read a text like "hallo" and why is putchar() able to print this text "hello"?
putchar is said to print a (one?) character each time it is called. So shouldn't putchar() only be able to print the first character of "Hallo", so "H"? Or is there a loop defined in the method putchar() that traverses the char sequence of the text passed to the method? And why am I able to pass a text to c when c is a) defined as int and b) when getchar is supposed to read a single character?
I'm using Code::Blocks on Windows and run applications on a console.