What do I need to do so the function isspace work in C

不想你离开。 提交于 2019-12-11 09:33:24

问题


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?

Thanks a lot for your help!

Cheers


回答1:


You need #include <ctype.h>.

However make sure you read the documentation carefully. Its interface is unintuitive, for historical reasons.

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) )

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 ) )

The same goes for all of the other is* functions in ctype.h




回答2:


You need:

#include <ctype.h>


来源:https://stackoverflow.com/questions/28654792/what-do-i-need-to-do-so-the-function-isspace-work-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!