C library function - isspace()
Description
C Library Function int isspace(int c) Checks whether the passed character is a whitespace character.
Standard whitespace characters include:
' ' (0x20) space (SPC) 空格符
'\t' (0x09) horizontal tab (TAB) 水平制表符
'\n' (0x0a) newline (LF) 换行符
'\v' (0x0b) vertical tab (VT) 垂直制表符
'\f' (0x0c) feed (FF) 换页符
'\r' (0x0d) carriage return (CR) 回车符
Declaration
Here is the declaration of the isspace() function.
int isspace(int c);
Parameters
- c -- This is the character to be checked.
Return Value
If c is a whitespace character, the function returns a nonzero value (true); otherwise it returns 0 (false).
Example
The following example demonstrates the use of the isspace() function.
#include
#include
int main()
{
int var1 = 't';
int var2 = '1';
int var3 = ' ';
if( isspace(var1) )
{
printf("var1 = |%c| 是空白字符\n", var1 );
}
else
{
printf("var1 = |%c| 不是空白字符\n", var1 );
}
if( isspace(var2) )
{
printf("var2 = |%c| 是空白字符\n", var2 );
}
else
{
printf("var2 = |%c| 不是空白字符\n", var2 );
}
if( isspace(var3) )
{
printf("var3 = |%c| 是空白字符\n", var3 );
}
else
{
printf("var3 = |%c| 不是空白字符\n", var3 );
}
return(0);
}
Let's compile and run the above program, which will produce the following result:
var1 = |t| 不是空白字符
var2 = |1| 不是空白字符
var3 = | | 是空白字符
C Standard Library -