Print character history

#include

#define ARRSIZ 127 - 33

int main(void) {
int i, c, nc;
float f[ARRSIZ];

nc = 0;
for(i = 0; i < ARRSIZ; i++) f[i] = 0.0;

while((c = getchar()) != EOF)
if(c >= 33 && c <= 127)
f[c - '!']++, nc++;

for(i = 0; i < ARRSIZ; i++)
if(f[i])
printf("%c\t%.2f\n", i + '!', 100 * f[i] / nc);

return 0;
}

No comments:

Post a Comment