Sunday, July 20, 2008

Find the count of the characters in a string


void findChars(char s[])
{
int count[128];
int l=strlen(s);
for(int i=0; i<128; i++)
count[i]=0;
for(int i=0; i<l; i++)
count[s[i]]++;
for(int i=0; i<128; i++) {
if(count[i]!=0)
printf("%c - %d\n", i, count[i]);
}
}

No comments:

Post a Comment