Hacker News new | past | comments | ask | show | jobs | submit
A common programming error in C is reading input as char rather than int.

https://man7.org/linux/man-pages/man3/fgetc.3.html

fgetc(3) and its companions always return character-by-character input as an int, and the reason is that EOF is represented as -1. An unsigned char is unable to represent EOF. If you're using the wrong return value, you'll never detect this condition.

However, if you don't receive an EOF, then it should be perfectly fine to cast the value to unsigned char without loss of precision.