Skip to content

Instantly share code, notes, and snippets.

@standage
Created September 16, 2013 17:19
Show Gist options
  • Select an option

  • Save standage/6583650 to your computer and use it in GitHub Desktop.

Select an option

Save standage/6583650 to your computer and use it in GitHub Desktop.
Count alphabetic characters from standard input.
#include <stdio.h>
int main()
{
int frequency[26];
int ch;
for (ch = 0; ch < 26; ch++)
frequency[ch] = 0;
while (1)
{
ch = fgetc(stdin);
if (ch == EOF) break;
if ('a' <= ch && ch <= 'z') // lower case
frequency[ch-'a']++;
else if ('A' <= ch && ch <= 'Z') // upper case
frequency[ch-'A']++;
}
for(ch = 0; ch < 26; ch++)
{
//if(frequency[ch] > 0)
// printf("%c: %d\n", 'A' + ch, frequency[ch]);
printf("%d\n", frequency[ch]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment