1、ctype.h中的函数
2、代码理解
#include<iostream>
#include<algorithm>
#include<ctype.h>
#include<cstring>
using namespace std;
int main()
{
char str[1007];
cin>>str;
int len = strlen(str);
for(int i=0;i<len; i++)
{
if(isalnum(str[i])) //判断是否是数字或者字母
{
if(isdigit(str[i])) //判断是否是数字
{
cout<<"是数字呀:"<<str[i]<<endl;
}
if(isalpha(str[i])) //判断是否是字母
{
if(islower(str[i])) //判断是否是小写字母
{
cout<<"小写改为大写:"<<char(toupper(str[i]))<<endl;//将小写字母改为大写字母
}
if(isupper(str[i])) //判断是否是大写字母
{
cout<<"大写改为小写:"<<char(tolower(str[i]))<<endl;//将大写字母改为小写字母
}
}
}
if(!isalnum(str[i]))
{
cout<<"不是字母也不是数字呀:"<<str[i]<<endl;
}
}
return 0;
}
运行结果:
其他函数可以自己上手玩一下哦~