Original Post
🔒 Locked
algorithm
Advertisement
//don't know the precise character codes by heart... or the difference between a and A. You'll need to edit the code if you want it to handle capital and small letters both correctly since afaik they're not subsequent...
int alphabet[NUM_CHARCTERS_IN_ALPHABET];
for(unsigned i = 0; i < strlen(str); i++)
{
alphabet[str[i] - 'a']++;
}
char buf[25];
for(unsigned i = 0; i < NUM_CHARCTERS_IN_ALPHABET; i++)
{
if(alphabet[i])
{
sprintf(buf, " appears %i times\0", alphabet[i]);
buf[0] = i + 'a';
cout << buf << endl;
}
}
untested
Crispy
edit: typo
[edited by - crispy on June 16, 2002 6:09:03 PM]
<LOL>...member since...what''s that?...today?...no, that''d make it too obvious...</LOL>
_____________________________
And the Phoenix shall rise from the ashes...
--Thunder_Hawk -- ¦þ
______________________________
_____________________________
And the Phoenix shall rise from the ashes...
--Thunder_Hawk -- ¦þ
______________________________
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement