R
randomtalk
hello, I'm doing an exercise in "The C Programming Language, Second
Edition". I just can't get one of the first chapter problem correct (I
do realize however that there are answer exist on the internet for the
book, but i want to know what's wrong with my program). So here is my
program:
#include <stdio.h>
#define LENGTH 255
int main()
{
int c, length[LENGTH], curLength, i, j;
while((c = getchar()) != EOF)
{
if((c == ' ') || (c == '\t') || (c== '\n'))
{
length[curLength]++;
curLength = 0;
}
else
curLength++;
}
for(i = 0; i < LENGTH; i++)
{
for(j = 0; j <= length; j++)
{
printf("=");
}
printf("\n");
}
}
What I don't get is that how come it would print innumerable =s (It
should print in rows and each row has =s symbolize how many words
contain that many letter, if no words has that many letter, it should
print an empty row). It seems to be to be stuck in a very long if not
infinite loop, but i can't find the culprit..
Can someone kindly point out my mistake? Thank you very much!
Edition". I just can't get one of the first chapter problem correct (I
do realize however that there are answer exist on the internet for the
book, but i want to know what's wrong with my program). So here is my
program:
#include <stdio.h>
#define LENGTH 255
int main()
{
int c, length[LENGTH], curLength, i, j;
while((c = getchar()) != EOF)
{
if((c == ' ') || (c == '\t') || (c== '\n'))
{
length[curLength]++;
curLength = 0;
}
else
curLength++;
}
for(i = 0; i < LENGTH; i++)
{
for(j = 0; j <= length; j++)
{
printf("=");
}
printf("\n");
}
}
What I don't get is that how come it would print innumerable =s (It
should print in rows and each row has =s symbolize how many words
contain that many letter, if no words has that many letter, it should
print an empty row). It seems to be to be stuck in a very long if not
infinite loop, but i can't find the culprit..
Can someone kindly point out my mistake? Thank you very much!