c标准库头文件<ctype.h>里的函数(C语言学习第一天)

1、isalpha()

(1)函数原型(我猜的):

int isalpha_(char ch)
{
	int ret=0;
	if(ch>='A'&&ch<='Z'){
		ret=1;
	}else if(ch>='a'&&ch<='z'){
		ret=2;
	}
	return ret;
}

(2)函数功能:检查ch是否是字母;

(3)样例;

#include<stdio.h>
int isalpha_(char ch)
{
	int ret=0;
	if(ch>='A'&&ch<='Z'){
		ret=1;
	}else if(ch>='a'&&ch<='z'){
		ret=2;
	}
	return ret;
}
int main(void)
{
	char ch='a';
	char ch1='1';
	if(isalpha_(ch)){
		printf("%c是字母\n",ch);
	}else{
		printf("%c不是字母\n",ch);
	}
	if(isalpha_(ch1)){
		printf("%c是字母",ch1);
	}else{
		printf("%c不是字母",ch1);
	}
	return 0;
}

输出:

a是字母
1不是字母
--------------------------------
Process exited after 0.03926 seconds with return value 0
请按任意键继续. . .

2、iscntrl()

(1)函数原型(我猜的):

int iscntrl_(char ch)
{
	int ret=0;
	if(ch>=0&&ch<32||ch==127){
		ret=1;
	}
	return ret;
}

(2)函数功能:检查ch是否为控制字符;

(3)样例:无

3、isdigit()

(1)函数原型(我猜的):

int isdigit_(char ch)
{
	int ret=0;
	if(ch>='0'&&ch<='9'){
		ret=1;
	}
	return ret;
}

(2)函数功能:检查ch是否是属于0-9的数字

(3)样例:

#include<stdio.h>
int isdigit_(char ch)
{
	int ret=0;
	if(ch>='0'&&ch<='9'){
		ret=1;
	}
	return ret;
}
int main(void)
{
	char ch='2';
	char ch1='a';
	if(isdigit_(ch)){
		printf("%c是数字\n",ch);
	}else{
		printf("%c不是数字\n",ch);
	}
	if(isdigit_(ch1)){
		printf("%c是数字",ch1);
	}else{
		printf("%c不是数字",ch1);
	}
	return 0;
}

输出:

2是数字
a不是数字
--------------------------------
Process exited after 0.08142 seconds with return value 0
请按任意键继续. . .

4、isgraph()

(1)函数原型(我猜的):

int isgraph_(char ch)
{
	int ret=0;
	if(ch>' '&&ch<='~'){
		ret=1;
	}
	return ret;
}

(2)函数功能:检查ch是否为可显示字符(不包括空格键);

(3)样例:

#include<stdio.h>
int isgraph_(char ch)
{
	int ret=0;
	if(ch>' '&&ch<='~'){
		ret=1;
	}
	return ret;
}
int main(void)
{
	char ch=' ';
	char ch1='a';
	if(isgraph_(ch)){
		printf("%c是可打印字符\n",ch);
	}else{
		printf("%c不是可打印字符\n",ch);
	}
	if(isgraph_(ch1)){
		printf("%c是可打印字符",ch1);
	}else{
		printf("%c不是可打印字符",ch1);
	}
	return 0;
}

输出:

 不是可打印字符
a是可打印字符
--------------------------------
Process exited after 0.08828 seconds with return value 0
请按任意键继续. . .

5、islower()

(1)函数原型(我猜的):

int islower_(char ch)
{
	int ret=0;
	if(ch>='a'&&ch<='z'){
		ret=1;
	}
	return ret;
}

(2)函数功能:检查ch是否为小写字母;

(3)样例:

#include<stdio.h>
int islower_(char ch)
{
	int ret=0;
	if(ch>='a'&&ch<='z'){
		ret=1;
	}
	return ret;
}
int main(void)
{
	char ch='A';
	char ch1='a';
	if(islower_(ch)){
		printf("%c是小写字母\n",ch);
	}else{
		printf("%c不是小写字母\n",ch);
	}
	if(islower_(ch1)){
		printf("%c是小写字母",ch1);
	}else{
		printf("%c不是小写字母",ch1);
	}
	return 0;
}

输出:

A不是小写字母
a是小写字母
--------------------------------
Process exited after 0.08176 seconds with return value 0
请按任意键继续. . .

6、isupper()

(1)函数原型(我猜的):

int islower_(char ch)
{
	int ret=0;
	if(ch>='A'&&ch<='Z'){
		ret=1;
	}
	return ret;
}

(2)函数功能:检查ch是否为大写字母;

(3)样例:

#include<stdio.h>
int islower_(char ch)
{
	int ret=0;
	if(ch>='A'&&ch<='Z'){
		ret=1;
	}
	return ret;
}
int main(void)
{
	char ch='A';
	char ch1='a';
	if(islower_(ch)){
		printf("%c是大写字母\n",ch);
	}else{
		printf("%c不是大写字母\n",ch);
	}
	if(islower_(ch1)){
		printf("%c是大写字母",ch1);
	}else{
		printf("%c不是大写字母",ch1);
	}
	return 0;
}

输出:

A是大写字母
a不是大写字母
--------------------------------
Process exited after 0.0769 seconds with return value 0
请按任意键继续. . .

7、tolower()

(1)函数原型(我猜的):

char tolower_(char ch)
{
	char ret=0;
    if(ch>='A'&&ch<='Z'){
    	ret=ch+32;
	}else{
		ret=ch;
	}
	return ret;
}

(2)函数功能:把大写字母转换为小写字母,否则返回本来的字符;

(3)样例:

#include<stdio.h>
char tolower_(char ch)
{
	char ret=0;
    if(ch>='A'&&ch<='Z'){
    	ret=ch+32;
	}else{
		ret=ch;
	}
	return ret;
}
int main(void)
{
	char ch='A';
	char ch1='6';
	char ch2='a';
	putchar(tolower_(ch));
	printf("\n");
    putchar(tolower_(ch1));
    printf("\n");
    putchar(tolower_(ch2));
	return 0;
}

输出:

a
6
a
--------------------------------
Process exited after 0.08938 seconds with return value 0
请按任意键继续. . .

8、toupper()

(1)函数原型(我猜的):

char tolower_(char ch)
{
	char ret=0;
    if(ch>='a'&&ch<='z'){
    	ret=ch-32;
	}else{
		ret=ch;
	}
	return ret;
}

(2)函数功能:把小写字母转换为大写字母,否则返回本来的字符;

(3)样例:

#include<stdio.h>
char tolower_(char ch)
{
	char ret=0;
    if(ch>='a'&&ch<='z'){
    	ret=ch-32;
	}else{
		ret=ch;
	}
	return ret;
}
int main(void)
{
	char ch='A';
	char ch1='6';
	char ch2='a';
	putchar(tolower_(ch));
	printf("\n");
    putchar(tolower_(ch1));
    printf("\n");
    putchar(tolower_(ch2));
	return 0;
}

输出:

A
6
A
--------------------------------
Process exited after 0.08062 seconds with return value 0
请按任意键继续. . .

9、isalnum()

(1)函数原型(我猜的):

int isalnum_(char ch)
{
	int ret=0;
	if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z'||ch>='0'&&ch<='9'){
		ret=1;
	}
	return ret;
}

(2)函数功能:检查字符是否为数字或字母;

(3)样例:

#include<stdio.h>
int isalnum_(char ch)
{
	int ret=0;
	if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z'||ch>='0'&&ch<='9'){
		ret=1;
	}
	return ret;
}
int main(void)
{
	char ch='g';
	char ch1='%';
	if(isalnum_(ch)){
		printf("%c是字母或数字\n",ch);
	}else{
		printf("%c不是字母或数字\n",ch);
	}
	if(isalnum_(ch1)){
		printf("%c是字母或数字",ch1);
	}else{
		printf("%c不是字母或数字",ch1);
	}
	return 0;
}

输出:

g是字母或数字
%不是字母或数字
--------------------------------
Process exited after 0.08536 seconds with return value 0
请按任意键继续. . .

10、isblank()

(1)函数原型(我猜的):

int isblank_(char ch)
{
	int ret=0;
	if(ch==' '||ch=='	'){
		ret=1;
	}
	return ret;
}

(2)函数功能:检查字符是否为空白字符(' '||'tab');

(3)样例:

#include<stdio.h>
int isblank_(char ch)
{
	int ret=0;
	if(ch==' '||ch=='	'){
		ret=1;
	}
	return ret;
}
int main(void)
{
	char ch='g';
	char ch1=' ';
	if(isblank_(ch)){
		printf("%c是空白字符\n",ch);
	}else{
		printf("%c不是空白字符\n",ch);
	}
	if(isblank_(ch1)){
		printf("%c是空白字符",ch1);
	}else{
		printf("%c不是空白字符",ch1);
	}
	return 0;
}

输出:

g不是空白字符
 是空白字符
--------------------------------
Process exited after 0.03764 seconds with return value 0
请按任意键继续. . .

11、isspace()

(1)函数原型(我猜的):

int isspace_(char ch)
{
	int ret=0;
	if(ch==' '||ch=='\t'||ch=='\r'||ch=='\n'||ch=='\a'||ch=='\f'){
		ret=1;
	}
	return ret;
}

(2)函数功能:检查ch是否为空格字符(' '||'\t'||'\r'||'\n'||'\v'||'\f');

(3)样例:

#include<stdio.h>
int isspace_(char ch)
{
	int ret=0;
	if(ch==' '||ch=='\t'||ch=='\r'||ch=='\n'||ch=='\a'||ch=='\f'){
		ret=1;
	}
	return ret;
}
int main(void)
{
	char ch='g';
	char ch1=' ';
	if(isspace_(ch)){
		printf("%c是空格字符\n",ch);
	}else{
		printf("%c不是空格字符\n",ch);
	}
	if(isspace_(ch1)){
		printf("%c是空格字符",ch1);
	}else{
		printf("%c不是空格字符",ch1);
	}
	return 0;
}a

输出:

g不是空格字符
 是空格字符
--------------------------------
Process exited after 0.08779 seconds with return value 0
请按任意键继续. . .

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值