为什么要求islower()和朋友处理EOF? [英] Why are islower() and friends required to handle EOF?

查看:122
本文介绍了为什么要求islower()和朋友处理EOF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么需要islower()和朋友来处理EOF,而putchar()和朋友则不必呢?

Why are islower() and friends required to handle EOF, whereas putchar() and friends don't have to?

为什么islower()不能像putchar()那样将int视为unsigned char?这是完全有意义的,因为无论如何我们都必须先检查EOF.另请参见为什么putchar()fputc()putc()的参数类型不是char?

Why isn't islower() treating int as unsigned char, as it is the case in putchar()? This would make total sense, because we have to check for EOF first anyway. See also Why the argument type of putchar(), fputc(), and putc() is not char?

推荐答案

因为我们还是必须先检查EOF.

because we have to check for EOF first anyway.

我们绝对不会.

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

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

This is totally legitimate code to skip whitespaces. Checking each character for EOF separately is a waste of time.

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

The ctype functions are made to handle EOF specifically to enable code like this.

另请参见此问题.

这篇关于为什么要求islower()和朋友处理EOF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆