I am trying to make my histogram print only a to z and not spaces or other symbols. From my code below how could I achieve this. I have set c to ignore case but i cannot figure out how to ignore white spaces and etc.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define READ 5000
main() {
int c;
int i;
int x;
int length[READ];
{
for (x = 0; x < READ; x++)
length[x] = 0;
while ((c = getchar()) != EOF) {
c = tolower(c); // ignores all cases.
length[c]++;
if (c == EOF)
break;
}
}
for (x = 0; x < READ; x++) {
if (length[x] > 0) {
printf("%c| ", x);
for (i = 1; i <= length[x] / 5; ++i) {
// since the value i is int when a value less than 5
// such as 4/5 appears as 0. 5/5 to 9/5 is 1 "x"
printf("X"); // prints an X for every 5 of a character
}
printf("\b\b\b\b\b\t\t\t(%d)", length[x]);
printf("\n"); // aligns the histogram with new line
}
}
}