- #1
dE_logics
- 742
- 0
Every time I start off with programming, I get stuck with these get and putchar functions.
First off, as appose to what's in the books, the getchar takes in more than a character...it can take in complete pages, forget strings.
Then the putchar only prints one character...after printing that, if it's called again, it's not that it'll print the next character that the variable has in store, but the same character again and again until we call getchar with the same variable assigned to it (for e.g. c = getchar()); NOW if putchar is called again, it will print the next character.
Surprisingly getchar, when called above, did not take in new inputs, but when it was called the first time, it did take new ones.
It appears that getchar() has a pointer applied on the variable which assigns to it. Assuming this variable to be c, if the function getchar() does not have anything stored in behalf of c, then it will take in fresh inputs.
Then, each time c = getchar() is called, instead of taking new inputs, this pointer which has been pointing to a character stored in c will now will point to the next character and putchar prints this pointed character.
Also I think the real information is stored in the function getchar(), since c = getchar() might destroy information in c if getchar() returns something.
I know I'm wrong...so can someone correct me?
First off, as appose to what's in the books, the getchar takes in more than a character...it can take in complete pages, forget strings.
Then the putchar only prints one character...after printing that, if it's called again, it's not that it'll print the next character that the variable has in store, but the same character again and again until we call getchar with the same variable assigned to it (for e.g. c = getchar()); NOW if putchar is called again, it will print the next character.
Surprisingly getchar, when called above, did not take in new inputs, but when it was called the first time, it did take new ones.
It appears that getchar() has a pointer applied on the variable which assigns to it. Assuming this variable to be c, if the function getchar() does not have anything stored in behalf of c, then it will take in fresh inputs.
Then, each time c = getchar() is called, instead of taking new inputs, this pointer which has been pointing to a character stored in c will now will point to the next character and putchar prints this pointed character.
Also I think the real information is stored in the function getchar(), since c = getchar() might destroy information in c if getchar() returns something.
I know I'm wrong...so can someone correct me?