C和指针之字符操作(<ctype.h>)

来源:互联网 发布:人工智能软件小冰 编辑:程序博客网 时间:2024/05/18 01:10

1、字符操作

在头文件<ctype.h>中
1、字符分类
islower(int a) 是否是小写
isupper(int a) 是否是大写


2、字符转换
int tolower(int ch)转换成小写
int woupper(int ch)转换成大写







2、测试Demo

#include <stdio.h>#include <ctype.h>int main(){    //字符分类    char a = 'A';    printf("islower(%c) is %d\n", a, islower(a));    char b = 'B';    printf("isupper(%c) is %d\n", b, isupper(b));    char c = 'C';    //是不是字母    printf("isalpha(%c) is %d\n", c, isalpha(c));    //字符转换    char d = 'D';    printf("tolower(%c) is %c\n", d, tolower(d));    char e = 'e';    printf("toupper(%c) is %c\n", e, toupper(c));    return 0;}






3、运行结果

1111deMacBook-Pro:dabian a1111$ gcc -g char.c -o char1111deMacBook-Pro:dabian a1111$ ./charislower(A) is 0isupper(B) is 1isalpha(C) is 1tolower(D) is dtoupper(e) is C