使用isalpha函数可以判断字符是否为字母,属于ctype.h头文件;但也包含在iostream头文件下;使用如下:
程序代码:
const int maxn = 210;
int main(){
char str[maxn];
while(gets(str)){
int len = strlen(str);
for(int i=0;i<len;i++){
if(isalpha(str[i]))
printf("%c",str[i]);
}
printf("\n");
}
return 0;
}
运行结果:
还有可以判断是否为数字的函数(isdigit):C/C++库函数(isdigit)判断字符是否为数字