Hey guys. Have been self teaching myself programming and got stuck on another problem. For problem 1-13 in the K&M, it asks for a program that makes a histogram of lengths of words. I figured that was a too too difficult and decided instead to just make a program that counts the numbers of words of different lengths, and to make it even easier I decided to just limit it to 10. Yet I can't even get that to work =\
Code:
#include <stdio.h>
main(){
#define IN 1
#define OUT 0
int c, i, j, state;
int word[10];
i = 0;
state = OUT;
for (j=0;j<=9;++j)
word[j]=0;
while ((c = getchar()) != EOF)
{
if ((c == ' '|| c == '\b'|| c == '\n') && state == IN )
{
state = OUT;
++word[i - '1'];
i = 0;
}
else if ((c==' '|| c=='\b'|| c=='\n') && state == OUT);
else
{
++i;
state == IN;
}
}
printf("The number of words length 1 2 3 4 5 6 7 8 9 10 is\n\t\t\t\t");
for (j=0;j<=9;++j)
printf("%d ", word[j]);
}
when I print it just prints out all 0's. Not quite sure what I'm doing wrong. Thanks in advance.