C 語言庫 - isblank() 函式



C 的ctype 庫的isblank() 函式用於檢查給定字元是否為空格字元。空格字元通常包括空格和水平製表符。

語法

以下是 C 庫中 isblank() 函式的語法:

int isblank(int c);

引數

此函式接受一個引數:

  • c - 要檢查的字元,作為 int 型別傳遞。它必須能夠表示為無符號字元或 EOF 的值。

返回值

如果字元為空格字元(空格 ' ' 或水平製表符 '\t'),則函式返回非零值(true)。否則返回 0(false)。

示例 1:檢查空格字元

這裡我們使用 isblank() 檢查空格字元 (' ') 是否為空格字元,它返回 true。

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

int main() {
   char ch = ' ';
   if (isblank(ch)) {
      printf("The character is a blank character.\n");
   } else {
      printf("The character is not a blank character.\n");
   }
   return 0;
}

輸出

以上程式碼產生以下結果:

The character is a blank character.

示例 2:檢查非空格字元

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

int main() {
   char ch = 'A';
   if (isblank(ch)) {
      printf("The character is a blank character.\n");
   } else {
      printf("The character is not a blank character.\n");
   }
   return 0;
}

輸出

執行以上程式碼後,我們得到以下結果:

The character is not a blank character.
廣告

© . All rights reserved.