isalnum ()-isxdigit ()- 测试整数值

格式

#include <ctype.h>
int isalnum(int c);
/* Test for upper- or lowercase letters, or decimal digit */
int isalpha(int c);
/* Test for alphabetic character */
int isblank(int c);
/* Test for blank or tab character */
int iscntrl(int c);
/* Test for any control character */
int isdigit(int c);
/* Test for decimal digit */
int isgraph(int c);
/* Test for printable character excluding space */
int islower(int c);
/* Test for lowercase */
int isprint(int c);
/* Test for printable character including space */
int ispunct(int c);
/* Test for any nonalphanumeric printable character */
/* excluding space */
int isspace(int c);
/* Test for whitespace character */
int isupper(int c);
/* Test for uppercase */
int isxdigit(int c);
/* Test for hexadecimal digit */
 

语言级别

ANSI

线程安全

语言环境敏感

这些函数的行为可能受当前语言环境的 LC_CTYPE 类别影响。 有关更多信息,请参阅 了解 CCSID 和语言环境

描述

< ctype.h > 列出的函数用整数值测试一个字符。

返回值

如果整数满足测试条件,那么这些函数返回非零值,如果不满足测试条件,那么返回零值。 整数变量 c 必须可表示为 无符号字符
注: EOF 是有效的输入值。

示例

此示例分析代码 0x0 与代码 UPPER_LIMIT之间的所有字符,打印 A 表示字母字符, AN 表示字母数字, B 表示空白或制表符, U 表示大写, L 表示小写, D 表示数字, X 表示十六进制数字, S 表示空格, PU 表示标点, PR 表示可打印字符, G 表示图形字符, C 表示控制字符。 此示例打印代码 (如果可打印)。

此示例的输出是一个由 256 行组成的表,其中显示从 0255 的字符,这些字符具有已测试的属性。
#include <stdio.h>
#include <ctype.h>
 
#define UPPER_LIMIT   0xFF
 
int main(void)
{
   int ch;
 
   for ( ch = 0; ch  <= UPPER_LIMIT; ++ch )
   {
      printf("%3d ", ch);
      printf("%#04x ", ch);
      printf("%3s ", isalnum(ch)  ? "AN" : " ");
      printf("%2s ", isalpha(ch)  ? "A"  : " ");
      printf("%2s ", isblank(ch)  ? "B"  : " ");
      printf("%2s",  iscntrl(ch)  ? "C"  : " ");
      printf("%2s",  isdigit(ch)  ? "D"  : " ");
      printf("%2s",  isgraph(ch)  ? "G"  : " ");
      printf("%2s",  islower(ch)  ? "L"  : " ");
      printf(" %c",  isprint(ch)  ? ch   : ' ');
      printf("%3s",  ispunct(ch)  ? "PU" : " ");
      printf("%2s",  isspace(ch)  ? "S"  : " ");
      printf("%3s",  isprint(ch)  ? "PR" : " ");
      printf("%2s",  isupper(ch)  ? "U"  : " ");
      printf("%2s",  isxdigit(ch) ? "X"  : " ");
 
      putchar('\n');
   }
}

相关信息