Playing around with code examples from K&R in Codeblocks on Windows 10 (Danish language). The following example works as expected:
#include <stdio.h> int main() { char c = 'a'; putchar(c); } However, the following prints a series of boxes with question marks, the same number as the number of characters I type:
#include <stdio.h> int main() { char c; while (c = getchar() != '\n') { putchar(c); } } So it looks like an encoding issue. When run, a command prompt opens with "C:\Users\username\Desktop\filename.exe" in the header, and my username contains the Danish character "å" which is replaced by a "Õ". The command prompt uses the CP 850 character set.
(By the way, I'm not checking if the character equals EOF, since that produces odd results. Pressing enter prints the expected number of boxes, plus one for \n, but it doesn't end the program.)
getcharreturns anint. This is important if you ever what to check forEOF(which you really should do even for input fromstdin).EOFis of typeint, andgetcharreturnsintnotchar. Stupid function name? Very much so. Which is why bothering with all the old stdio.h crap in K&R is mostly a waste of time. Nobody writes console programs since 20 years back.ABC?