Created
September 16, 2013 17:19
-
-
Save standage/6583650 to your computer and use it in GitHub Desktop.
Count alphabetic characters from standard input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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