Relative Content

Tag Archive for cc89ansi-c

K&R recommands to use the int when reading character using getchar()?

The problem is distinguishing the end of the input from valid data. The
solution is that getchar returns a distinctive value when there is no more input,
a value that cannot be confused with any real character. This value is called EOF,
for “end of file.” We must declare c to be a type big enough to hold any value
that getchar returns. We can’t use char since c must be big enough to hold
EOF in addition to any possible char. Therefore we use int.