Why islower () and friends should handle EOF?

Why do islower()friends need to process EOF, while putchar()friends do not?

Why is it islower()not treated intlike unsigned char, how does this take place in putchar()? This will make general sense, because we must first check EOF. See Also Why type of argument putchar(), fputc()and putc()not char?

+3
source share
2 answers

because we must first check the EOF.

We absolutely do not.

int c;
while(isspace(c=fgetc(fp)));
if (c==EOF) ...

This is completely legal code for skipping spaces. Checking each character for EOF separately is a waste of time.

ctype EOF .

. .

+4

EOF , (, false). EOF <ctype.h>.

, int char, , , , , :

int c;
while ((c =getchar()) != EOF) {
    if (islower(c)) {
        ...
    } else if (isdigi(c)) {
        ...
    }
}

islower(char) islower(int), , . , int getchar "", , .

+1

Source: https://habr.com/ru/post/1661545/


All Articles