本文共 584 字,大约阅读时间需要 1 分钟。
#include#include int letter_count=0,num_count=0,other_count=0;//获取字符串中字母数,数字数,其他字符数void char_count(char *str){ int i=0; while(*(str+i) != '\0'){ char c = *(str+i); if( c >= '0' && c <= '9') num_count++; else if( (c >= 'A' && c <='Z') || (c >= 'a' && c <= 'z')) letter_count++; else other_count++; i++; }}int main() { char str[50]; gets(str); char_count(str); printf("字母数为:%d\t数字数:%d\t其他字符数为:%d\n",letter_count,num_count,other_count); system("pause"); return EXIT_SUCCESS;}
转载地址:http://yizhz.baihongyu.com/