gpt4 book ai didi

c - 为什么需要 islower() 和 friend 来处理 EOF?

转载 作者:太空狗 更新时间:2023-10-29 16:10:44 25 4
gpt4 key购买 nike

为什么 islower() 和 friend 需要处理 EOF,而 putchar() 和 friend 不需要?

为什么 islower() 不将 int 视为 unsigned char,就像 putchar()< 中的情况一样?这是完全合理的,因为无论如何我们都必须首先检查 EOF。另见 Why the argument type of putchar(), fputc(), and putc() is not char?

最佳答案

because we have to check for EOF first anyway.

我们绝对不会。

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

这是跳过空格的完全合法的代码。分别检查每个字符的 EOF 是浪费时间。

ctype 函数专门用于处理 EOF 以启用这样的代码。

另见 this question .

关于c - 为什么需要 islower() 和 friend 来处理 EOF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40716908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com