isspace() works if the input is representable as unsigned char or equal to EOF
.
getchar() reads the next character from stdin.
When getch
According to C11 WG14 draft version N1570:
§7.21.7.6/2 The
getchar
function is equivalent togetc
with the argument stdin.§7.21.7.5/2 The
getc
function is equivalent tofgetc
...§7.21.7.1/2 [
!=EOF
case] ...thefgetc
function obtains that character as anunsigned char
converted to anint
...text in [...] is mine.
i.e.,
isspace()
accepts getchar()
valuesgetchar()!=EOF
values are representable as unsigned char
If you think it is too obvious ("what else can it be"), think again. For example, in the related case: isspace(CHAR_MIN)
may be undefined i.e., it may be undefined behavior to pass a character to a character classification function!
If UCHAR_MAX > INT_MAX
the result may be implementation-defined:
§6.3.1.3/3 Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.