//输入一串字符,显示出来出各字符出现的次数。
//例如: 输入This is a pencil. 则各字符出现次数分别为:T:1
//用函数完成 !
满意回答: 2012-5-7 17:10
#include
void PROC(char *p)
{
int i;
char b[256] = {0};
while(*p != '\0') b[*p++]++;
for (i = 32; i < 128; i++) if (b[i]) printf("%c, %d\n", i, b[i]);
}
void main()
{
char a[200];
printf("Please Input String: \n\n");
gets(a);
PROC(a); //调用函数完成.
printf("\n\nByebye.\n\n");
}
//-------------------------------
程序执行时,显示如下:
Please Input String:
This is a pencil.
, 3
., 1
T, 1
a, 1
c, 1
e, 1
h, 1
i, 3
l, 1
n, 1
p, 1
s, 2
Byebye.
Press any key to continue
//=================================
原题网址:http://zhidao.baidu.com/question/420369264.html//=================================