isdigit:用于检查其参数是否为十进制数字字符。若参数c为阿拉伯数字0~9,则返回非0值,否则返回0。
isalpha:判断字符ch是否为英文字母,若为英文字母,返回非0(小写字母为2,大写字母为1)。若不是字母,返回0。
toupper:功能是把小写字母变成大写字母
tolower:功能是把大写字母变成小写字母
头文件:#include <ctype.h>
样例:
#include <bits/stdc++.h>
using namespace std;
int main()
{
char a='2';
char c='n';
char d='N';
cout<<"数字测试"<<endl;
cout<<isdigit(a)<<endl;
cout<<isdigit(c)<<endl;
cout<<endl<<"字母测试"<<endl;
cout<<isalpha(c)<<endl;
cout<<isalpha(d)<<endl;
cout<<isalpha(a)<<endl;
cout<<endl<<"小写字母变大写字母"<<endl;
putchar(toupper(c));
cout<<endl;
cout<<endl<<"大写字母变小写字母"<<endl;
putchar(tolower(d));
cout<<endl;
return 0;
}
输出: