First of all, this is not a problem nor a bug. I just wanted to know how string input from stdin is handled in getchar(). Also, is the same method used for putchar() but just in reverse? These two functions are confusing me since getchar and putchar both take a single character from the input/ print a single char to the output. Is there like a special buffer for the string?
working code:
#include <stdio.h>
int main() {
int c;
c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
}
return 0;
}
getcharjust take a single character at each call fromstdin, one after another.putchar()prints the the actual character. This repetition is what thewhileloop is for.stdin. When you type something in the terminal the characters typed are added tostdinand all standard input functions that don't specify a file read the characters from it automatically. (Note that when you press Enter the character new line\nis added to the list of characters.)