Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- #define TOLOWER 32
- #define LETTER_START 97
- #define ALPHABET_SIZE 26
- char toLowerCase (char character);
- int main (int argc, char *argv[]) {
- char readChar;
- int arrayPos = 0;
- readChar = toLowerCase(getchar());
- int alphabetFreq[26] = {0};
- while (readChar != -1) {
- if (readChar >= 'a' && readChar <= 'z') {
- arrayPos = readChar - LETTER_START;
- alphabetFreq[arrayPos]++;
- //printf ("%c = %d\n", readChar, arrayPos);
- }
- readChar = toLowerCase(getchar());
- }
- char startChar = 'a';
- int count = 0;
- while (count < ALPHABET_SIZE){
- printf("%c : %d\n", startChar, alphabetFreq[count]);
- startChar ++;
- count ++;
- }
- return EXIT_SUCCESS;
- }
- char toLowerCase (char character) {
- if (character >= 'A' && character <= 'Z') {
- character += TOLOWER;
- }
- return character;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement