我需要怎么做才能使函数在C中工作 [英] What do I need to do so the function isspace work in C
问题描述
当我尝试使用cc编译C程序时,收到警告,提示我具有隐式函数声明isspace。这不是标准C库的一部分吗?我需要执行哪种导入才能使我的功能正常运行?
When I try to compile my C program with cc I get a warning that I have an implicit function declaration isspace. Isn't this part of the standard C library? Which import do I need to do so my function runs properly?
非常感谢您的帮助!
欢呼声
推荐答案
您需要#包括< ctype.h>
。
不过,请务必仔细阅读文档。出于历史原因,它的界面不直观。
However make sure you read the documentation carefully. Its interface is unintuitive, for historical reasons.
它设计为仅在 0
到 UCHAR_MAX
(通常为255)-与 getchar()
函数返回的值相同。例如:
It's designed to work only on a value from 0
to UCHAR_MAX
(usually 255) -- the same sort of value that is returned by the getchar()
function. For example:
int ch = getchar();
if ( isspace(ch) )
请勿将其与 char
。如果您有一个 char
要检查空格,则必须将其转换为预期范围;例如通过强制转换为(未签名字符)
:
Do not use it with a char
. If you have a char
that you want to check for whitespace, it must be converted to be in the expected range; e.g. by a cast to (unsigned char)
:
char ch = 't';
if ( isspace( (unsigned char)ch ) )
对于所有 ctype.h
这篇关于我需要怎么做才能使函数在C中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!