C语言判断一字符串中只有汉字或者英文字母的方法

代码如下:

include #include bool isCHNENG(char str1) { unsigned int temp,len,num_char=0,num_chin=0; len=strlen(str1); temp=(unsigned int)str1; while(temp) { if(!numchin&&(temp>='a'&&temp<='z')||(temp>='A'&&temp<='Z')) numchar=1; else if(!numchar&&(temp>0xa0)) numchin=1; else return false; str1++; temp=(unsigned int)*str1; } return true; } int main(void) { char letter[]="I am chinese"; if(isCHNENG(letter)) //测试 printf("ok, letter! "); else printf("NO WAY, letter! "); return 0; }

comments powered by Disqus