當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。