C 庫函數 - iscntrl()

C 標準庫 - <ctype.h> C 標準庫 - <ctype.h>

描述

C 庫函數 void iscntrl(int c) 檢查所傳的字元是否是控制字元。

根據標準 ASCII 字元集,控制字元的 ASCII 編碼介於 0x00 (NUL) 和 0x1f (US) 之間,以及 0x7f (DEL),某些平臺的特定編譯器實現還可以在擴展字元集(0x7f 以上)中定義額外的控制字元。

聲明

下麵是 iscntrl() 函數的聲明。

int iscntrl(int c);

參數

  • c -- 這是要檢查的字元。

返回值

如果 c 是一個控制字元,則該函數返回非零值,否則返回 0。

實例

下麵的實例演示了 iscntrl() 函數的用法。

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

int main ()
{
   int i = 0, j = 0;
   char str1[] = "all \a about \t programming";
   char str2[] = "zaixian \n tutorials";

   /* 輸出字串直到控制字元 \a */
   while( !iscntrl(str1[i]) )
   {
      putchar(str1[i]);
      i++;
   }

   /* 輸出字串直到控制字元 \n */
   while( !iscntrl(str2[j]) )
   {
      putchar(str2[j]);
      j++;
   }

   return(0);
}

讓我們編譯並運行上面的程式,這將產生以下結果:

all zaixian

C 標準庫 - <ctype.h> C 標準庫 - <ctype.h>