The exercise was to print a histogram of the different characters in the input. At the bottom is my code where I break the different characters into 3 categories a,b, or other, to extrapolate to more categories of characters if the code is successful. But it doesn't have the output I want, for example, for input ab cd
I expect
x
xxx
---
abo
t
h
e
r
but all I get is
---
abo
t
h
e
r
Here's my attempt:
#include<stdio.h>
main()
{
int i,c,b, max;
int array[3] = {0,0,0};
while( (c = getchar()) != EOF){
if(c== 'a')
++array[0];
else if(c== 'b')
++array[1];
else if(c=='\n' ||c=='\t' || c==' '){}
else ++array[2];
}
array[0]=max;
i=0;
while(i<3){
if(max>=array[i])
{}
else array[i]=max;
++i;
}
i=0;
max=b;
while(i<b){
if(array[0]>=max){
putchar('x');}
else putchar(' ');
if(array[1]>=max) {
putchar('x');}
else putchar(' ');
if (array[2]>=max){
putchar('x\n');}
else putchar(' \n');
--max;
++i;
}
printf("---\nabo\n t\n h\n e\n r");
}