C 库函数 - iscntrl()

C 语言教程 · 2019-02-22 19:57:45

描述

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[] = "Codercto \n tutorials";
  
   /* 输出字符串直到控制字符 \a */
   while( !iscntrl(str1[i]) ) 
   {
      putchar(str1[i]);
      i++;
   }
  
   /* 输出字符串直到控制字符 \n */
   while( !iscntrl(str2[j]) ) 
   {
      putchar(str2[j]);
      j++;
   }
   
   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果:

all Codercto 

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

The Art of Computer Programming, Volume 4,  Fascicle 3

The Art of Computer Programming, Volume 4, Fascicle 3

Donald E. Knuth / Addison-Wesley Professional / 2005-08-05 / USD 19.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 4, Fascicle 3》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具