判断是否是控制字符

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

/*
判断是控制字符(ASCII 0-31和127)的库函数:
满足指定的条件,返回非0;否则返回0.
iscntrl(c)
*/

/***************
 * 输入:要判断的字符。
 * 输出:是空白,返回1;其他,返回0.
 **************/
int my_iscntrl(unsigned char c)
{
	if ((c >= 0 && c <= 31) || c == 127) {
		return 1;
	}
	return 0;
}

int main(void)
{

	printf("%d\n", my_iscntrl('\n'));
	printf("%d\n", iscntrl('6'));

	return 0;
}

 

输出:

1

0

posted @ 2012-12-04 19:25  helloweworld  阅读(380)  评论(0编辑  收藏  举报