假定只有ASCII字符,构造一个统计可见字符的整数数组,大概要100个元素(初始化为0),由于字符和整数的统一性,你可以这样来填充这个数组 #include <stdio.h> #include <string.h> /*统计一个字符串中出现字符的个数*/ /*可见字符差不多有100个*/ int main() { int count[100] = {0}; int i; char s[] = "abadfdkff%#$3203849349384389y1"; for (i = 0;i < strlen(s);i++) { if (s[i] == '/0') { break; } count[(int)(s[i])]++; } for (i = 0;i < 100;i++) { if (count[i] > 0) { printf("%5c%5d/n",i,count[i]); } } return 0; }