当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


C语言 isspace()用法及代码示例

此函数接受一个字符的参数并检查该字符是否为空格字符。如果字符不是空格字符,则函数返回零,如果字符是空格字符,则返回 ‘one’。

使用这个函数相当简单,因为它只需要一个 char 类型的字符并返回一个整数。整数值确定字符是否为空格字符。

该函数可用于识别字符数组中的空格字符或用户在某一点的输入。

例:

    Input character is:'a'
    Function will return 0


    Input character is:' '
    Function will return 1

ctype.h - C 中的 isspace() 函数示例


#include <stdio.h>
#include <ctype.h>

int main()
{
    // defining the type of variable
    char a,b;

    // assigning the value of variables
    a = 'A';
    b = '\n';

    // condition to test the space characters
    if (isspace(a) != 0)
    {
        printf("%c is a space character\n\n", a);
    }
    else
    {
        printf("%c is not a space character\n\n", a);
    }

    if (isspace(b) != 0)
    {
        printf("Value of b is a space character\n");
    }
    else
    {
        printf("Value of b is not a space character\n");
    }

    return 0;
}

输出

ctype.h - isspace()  in c language



相关用法


注:本文由纯净天空筛选整理自Abhishek Sharma大神的英文原创作品 isspace() function of ctype.h in C。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。