函式
<cctype>

isspace

int isspace ( int c );
檢查字元是否為空白字元
檢查 c 是否是空白字元

對於“C”locale,空白字元是以下任意一種:
' '(0x20)空格 (SPC)
'\t'(0x09)水平製表符 (TAB)
'\n'(0x0a)換行符 (LF)
'\v'(0x0b)垂直製表符 (VT)
'\f'(0x0c)換頁符 (FF)
'\r'(0x0d)回車符 (CR)

其他 locales 可能會將不同的字元集視為空白字元,但絕不會是 isalnum 返回 true 的字元。

有關不同ctype函式對標準 ASCII 字元集中每個字元返回值的詳細圖表,請參閱 <cctype> 標頭檔案的參考。

在 C++ 中,此函式的一個針對特定 locale 的模板版本 (isspace) 存在於標頭檔案 <locale> 中。

引數

c
要檢查的字元,轉型為int型別,或EOF.

返回值

如果 c 確實是空白字元,則返回一個非零值(即true) 如果 c 確實是一個空白字元。否則返回零 (即false)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* isspace example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
  char c;
  int i=0;
  char str[]="Example sentence to test isspace\n";
  while (str[i])
  {
    c=str[i];
    if (isspace(c)) c='\n';
    putchar (c);
    i++;
  }
  return 0;
}

這段程式碼逐個字元地列印 C 字串,並將任何空白字元替換為換行符。 輸出
Example
sentence
to
test
isspace


另見