Print a histogram of the frequency of characters entered.

Source:

/* print the input one word per line. */
/* word defined by letters surrounded by whitespace. */
#include "stdio.h"

#define TRUE 1
#define FALSE 0

typedef signed char bool; 

int main(int argc, char *argv[])
{
  int character = ' ';
  bool running = TRUE;
  int letter_freq[26] = {0};
  int i=0;

  printf("Type fewer than 1024 words. I will print a histogram showing the frequency of letters.\n"
      "[Enter] to submit. EOF (ctrl+d) to quit.\n");
  printf("--------------------------------------------------------------------------------------\n");

  while(running)
  {
    character = getchar();

    if(character == '\n' || character == ' ' || character == '\t' || character == EOF)
    {
      /* do nothing. */
    }
    else
    {
      /* count the characters for the histogram. */
      switch(character)
      {
        case 'a':
        case 'A':
          letter_freq[0]++;
          break;

        case 'b':
        case 'B':
          letter_freq[1]++;
          break;

        case 'c':
        case 'C':
          letter_freq[2]++;
          break;

        case 'd':
        case 'D':
          letter_freq[3]++;
          break;

        case 'e':
        case 'E':
          letter_freq[4]++;
          break;

        case 'f':
        case 'F':
          letter_freq[5]++;
          break;

        case 'g':
        case 'G':
          letter_freq[6]++;
          break;

        case 'h':
        case 'H':
          letter_freq[7]++;
          break;

        case 'i':
        case 'I':
          letter_freq[8]++;
          break;

        case 'j':
        case 'J':
          letter_freq[9]++;
          break;

        case 'k':
        case 'K':
          letter_freq[10]++;
          break;

        case 'l':
        case 'L':
          letter_freq[11]++;
          break;

        case 'm':
        case 'M':
          letter_freq[12]++;
          break;

        case 'n':
        case 'N':
          letter_freq[13]++;
          break;

        case 'o':
        case 'O':
          letter_freq[14]++;
          break;

        case 'p':
        case 'P':
          letter_freq[15]++;
          break;

        case 'q':
        case 'Q':
          letter_freq[16]++;
          break;

        case 'r':
        case 'R':
          letter_freq[17]++;
          break;

        case 's':
        case 'S':
          letter_freq[18]++;
          break;

        case 't':
        case 'T':
          letter_freq[19]++;
          break;

        case 'u':
        case 'U':
          letter_freq[20]++;
          break;

        case 'v':
        case 'V':
          letter_freq[21]++;
          break;

        case 'w':
        case 'W':
          letter_freq[22]++;
          break;

        case 'x':
        case 'X':
          letter_freq[23]++;
          break;

        case 'y':
        case 'Y':
          letter_freq[24]++;
          break;

        case 'z':
        case 'Z':
          letter_freq[25]++;
          break;

        default:
          break;
      }
    }

    /* Test for EOF to quit here.*/
    if(character == EOF)
    {
      printf("\n");
      running = FALSE;
    }
  }

  printf("--------------------------------------------------------------------------------------\n");



  int o = 0;

  /* print out our histogram. */
  for(i=0; i<26; i++)
  {
    /* first print the letter of each line. */
    /* this uses an offset to display the correct ASCII. */
    printf("%c\t|", i+65);

    /* then print the frequency using some ascii art. */
    for(; o<letter_freq[i]; o++)
    {
      printf("=");
    }
    /* format for the next line. */
    printf("\n");

    /* reset o. */
    o = 0;
  }

  printf("--------------------------------------------------------------------------------------\n");
  return 0;
}

Output:

Type fewer than 1024 words. I will print a histogram showing the frequency of letters.
[Enter] to submit. EOF (ctrl+d) to quit.
--------------------------------------------------------------------------------------
A quick red fox jumps over the lazy brown dog
--------------------------------------------------------------------------------------
A	|==
B	|=
C	|=
D	|==
E	|===
F	|=
G	|=
H	|=
I	|=
J	|=
K	|=
L	|=
M	|=
N	|=
O	|====
P	|=
Q	|=
R	|===
S	|=
T	|=
U	|==
V	|=
W	|=
X	|=
Y	|=
Z	|=
--------------------------------------------------------------------------------------