字符处理函数库中的函数及其作用

字符处理库函数 <ctype.h> 包含了用于对字符数据进行测试和操作的函数。每个函数都接收一个unsigned char 字符(用整数表示)或EOF作为实参。

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

int main()
{
	printf("%s\n%s%s\n%s%s\n", "According to isdigit:", isdigit('8') ? "8 is a " : "8 is not a ", "digit", isdigit('#') ? "# is a " : "# is not a ", "digit");
	printf("判断数字是否为(0 到 9)\n\n");

	printf("%s\n%s%s\n%s%s\n%s%s\n%s%s\n", "According to isalpha:",
		isalpha('A') ? "A is a " : "A is not a ", "letter",
		isalpha('b') ? "b is a " : "b is not a ", "letter",
		isalpha('&') ? "& is a " : "& is not a ", "letter",
		isalpha('4') ? "4 is a " : "4 is not a ", "letter");
	printf("判断字母是否为(大写:A 到 Z 或 小写 a 到 z)\n\n");

	printf("%s\n%s%s\n%s%s\n%s%s\n", "According to isalnum:",
		isalnum('A') ? "A is a " : "A is not a ", "digit or letter",
		isalnum('8') ? "8 is a " : "8 is not a ", "digit or letter",
		isalnum('#') ? "# is a " : "# is not a ", "digit or letter");
	printf("判断是否为数字或字母\n\n");

	printf("%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n", "According to isxdigit:",
		isxdigit('F') ? "F is a " : "F is not a ", "hexadecimal digit",
		isxdigit('J') ? "J is a " : "J is not a ", "hexadecimal digit",
		isxdigit('7') ? "7 is a " : "7 is not a ", "hexadecimal digit",
		isxdigit('S') ? "S is a " : "S is not a ", "hexadecimal digit",
		isxdigit('f') ? "f is a " : "f is not a ", "hexadecimal digit");
	printf("判断是否为十六进制数字\n\n");

	printf("%s\n%s%s\n%s%s\n%s%s\n%s%s\n", "According to islower:",
		islower('p') ? "p is a " : "p is not a ", "lowercase letter",
		islower('P') ? "P is a " : "P is not a ", "lowercase letter",
		islower('5') ? "5 is a " : "5 is not a ", "lowercase letter",
		islower('!') ? "! is a " : "! is not a ", "lowercase letter");
	printf("判断字母是否为小写字母\n\n");

	printf("%s\n%s%s\n%s%s\n%s%s\n%s%s\n", "According to isupper:",
		isupper('D') ? "D is an " : "D is not an ", "uppercase letter",
		isupper('d') ? "d is an " : "d is not an ", "uppercase letter",
		isupper('8') ? "8 is an " : "8 is not an ", "uppercase letter",
		isupper('&') ? "& is an " : "& is not an ", "uppercase letter");
	printf("判断字母是否为大写字母\n\n");

	printf("%s%c\n%s%c\n%s%c\n%s%c\n",
		"u is coverted to uppercase is ", toupper('u'),
		"7 is coverted to uppercase is ", toupper('7'),
		"$ is coverted to uppercase is ", toupper('$'),
		"L is coverted to uppercase is ", tolower('L'));
	printf("函数tolower将一个大写字母转换成小写字母并返回这个小写字母,若实参不是大写字母,则返回未改变的实参\n");
	printf("函数toupper将一个小写字母转换成大写字母并返回这个大写字母,若实参不是小写字母,则返回未改变的实参\n\n");

	printf("%s\n%s%s%s\n%s%s%s\n%s%s\n", "According to isspace:",
		"Newline", isspace('\n') ? " is a " : " is not a ", "whitespace character", "Horizontal tab",
		isspace('\t') ? " is a " : " is not a ", "whitespace character",
		isspace('%') ? "% is a " : "% is not a ", "whitespace character");
	printf("判断是否是空白字符包括(空格符(' '),换页符('\\f'),换行符('\\n'),回车符('\\r'),水平制表符('\\t'),垂直制表符('\\v')\n\n");

	printf("%s\n%s%s%s\n%s%s\n", "According to iscntrl:",
		"Newline", iscntrl('\n') ? " is a " : " is not a ", "control character",
		iscntrl('$') ? "$ is a " : "$ is not a ", "control character");
	printf("判断是否是控制字符包括(报警符('\\a'),换页符('\\f'),换行符('\\n'),回车符('\\r'),水平制表符('\\t'),垂直制表符('\\v'),退格符('\\b')\n\n");
	
	printf("%s\n%s%s\n%s%s\n%s%s\n", "According to ispunct:",
		ispunct(';') ? "; is a " : "; is not a ", "punctuation character",
		ispunct('Y') ? "Y is a " : "Y is not a ", "punctuation character",
		ispunct('#') ? "# is a " : "# is not a ", "punctuation character");
	printf("判断是否是一个除空格、数字、字母以外的可打印字符\n\n");

	printf("%s\n%s%s\n%s%s%s\n", "According to isprint:",
		isprint('$') ? "$ is a ": "$ is not a ", "printing character",
		"Alert", isprint('\a') ? " is a " : " is not a ", "printing character");
	printf("判断是否是一个可以打印在屏幕上的字符\n\n");

	printf("%s\n%s%s\n%s%s%s\n", "According to isgraph:",
		isgraph('Q') ? "Q is a " : "Q is not a ", "printing character other than space",
		"Space", isgraph(' ') ? " is a " : " is not a ", "printing character other than space");
	printf("判断是否是一个可以打印在屏幕上的字符(不包含空格符)\n\n");
	return 0;
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

枳洛淮南✘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值