Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4.  
  5. #define TOLOWER 32
  6. #define LETTER_START 97
  7. #define ALPHABET_SIZE 26
  8.  
  9. char toLowerCase (char character);
  10.  
  11. int main (int argc, char *argv[]) {
  12.     char readChar;
  13.     int arrayPos = 0;
  14.    
  15.     readChar = toLowerCase(getchar());
  16.    
  17.     int alphabetFreq[26] = {0};
  18.    
  19.     while (readChar != -1) {
  20.         if (readChar >= 'a' && readChar <= 'z') {
  21.             arrayPos = readChar - LETTER_START;
  22.             alphabetFreq[arrayPos]++;
  23.             //printf ("%c = %d\n", readChar, arrayPos);
  24.         }
  25.         readChar = toLowerCase(getchar());
  26.     }
  27.    
  28.     char startChar = 'a';
  29.     int count = 0;
  30.     while (count < ALPHABET_SIZE){
  31.         printf("%c : %d\n", startChar, alphabetFreq[count]);
  32.         startChar ++;
  33.         count ++;
  34.     }
  35.     return EXIT_SUCCESS;
  36. }
  37.  
  38. char toLowerCase (char character) {
  39.     if (character >= 'A' && character <= 'Z') {
  40.         character += TOLOWER;
  41.     }
  42.  
  43.     return character;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement