(standard c libraries translation)isalpha家族

所需头文件:

#include <ctype.h>


isalnum

checks for an alphanumeric character; it is equivalent to (isalpha(c) || isdigit(c)).
检查是否是含有字母或者数字的字符,等同于isalpha||isdigit

isalpha
checks  for  an alphabetic character; in the standard "C" locale, it is equivalent to (isupper(c) || islower(c)).  In some locales, there may be
additional characters for which isalpha() is true—letters which are neither upper case nor lower case.
检测是否是字母字符,在标准c环境下等同于isupper||islower,在其他环境下,isalpha可能有其他增加的字符,既不是upper case,也不是lower case

isascii
checks whether c is a 7-bit unsigned char value that fits into the ASCII character set
检测是否是一个7-bit的unsigned char类型,并且属于ASCII字符集


isblank
checks for a blank character; that is, a space or a tab
检测是否是一个空白的字符,也就是空格或者tab

iscntrl
checks for a control character
检测是否是一个控制字符

isdigit
checks for a digit (0 through 9)
检测是否是一个数字字符(0到9)

isgraph
checks for any printable character except space
检测是否是一个除空格以外的可打印字符

islower
checks for a lower-case character
检测是否是一个小写字母的字符

isprint
checks for any printable character including space
检测是否是可打印字符,包括空格在内

ispunct
checks for any printable character which is not a space or an alphanumeric character
检测是否是可打印字符,不包括空格,字母,数字等字符

isspace
checks for white-space characters.  In the "C" and "POSIX" locales, these are: space, form-feed ('\f'), newline ('\n'), carriage return  ('\r'),
horizontal tab ('\t'), and vertical tab ('\v').
检测是否是空白字符,在c和POSIX环境下,包括:space,'\f','\n','\r','\t','\v'

isupper
checks for an uppercase letter
检测是否是大写字母的字符

isxdigit
checks for a hexadecimal digits, that is, one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F

检测是否是16进制字符,包括0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F


返回值:

The values returned are nonzero if the character c falls into the tested class, and a zero value if not

如果被检测的字符是符合测试的字符集(也就是检测为真)就返回非0值,否则就是返回0值



学以致用,贴上一个test case

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

int main(int argc, char **argv)
{
	if (argc != 2) {
		printf("usage:./a.out <char>\n");
		return -1;
	}
	
	int tmp = *argv[1];
	printf("tmp = %d\n", tmp);

	if (isalnum(tmp) != 0) {
		printf("it's num or char\n");
	}

	if (isalpha(tmp) != 0) {
		printf("it's char\n");
	}

	if (isascii(tmp) != 0) {
		printf("it's ascii\n");
	}

	if (isblank(tmp) != 0) {
		printf("it's space or tab\n");
	}

	if (iscntrl(tmp) != 0) {
		printf("it's control char\n");
	}

	if (isdigit(tmp) != 0) {
		printf("it's digit\n");
	}

	if (isgraph(tmp) != 0) {
		printf("it's printable not include space\n");
	}

	if (islower(tmp) != 0) {
		printf("it's lower char\n");
	}

	if (isprint(tmp) != 0) {
		printf("it's printable include space\n");
	}

	if (isspace(tmp) != 0) {
		printf("it's space\n");
	}

	if (ispunct(tmp) != 0) {
		printf("it's not space, digit or alpha\n");
	}

	if (isupper(tmp) != 0) {
		printf("it's upper char\n");
	}

	if (isxdigit(tmp) != 0) {
		printf("it's hex num\n");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值