I’m not exactly sure whether or not this is a silly question, but I guess I will find out soon enough.
I’m having problems understanding exactly how getc and getwc work. It’s not that I can’t use them, but more like I don’t know exactly what they do. int and getc return most characters if I `printf(“%c”) them, including multibyte like € or even £.
My question is: how exactly do these functions work, how do they read stdin exactly? Explanations and good pointers to docs much appreciated.
Edit: Please, read the comment I left in William’s answer. It helps clarify the level of detail I’m after.
If you are on a system with 8-bit chars (that is, UCHAR_MAX == 255) then getc() will return a single 8-bit character. The reason it returns an int is so that the EOF value can be distinguished from any of the possible character values. This is almost any system you are likely to come across today.
The reason that fgetc() is apparently working for multibyte characters for you is because the bytes making up the multibyte character are being read in seperately, written out seperately and then interpreted as a multibyte character by your console. If you change your printf to:
(that is, put a space after each character) then you should see multibyte characters broken up into their constituent bytes, which will probably look quite weird).