Code:
for(ii = 0, j = 0; j <= m; ++j, ++ii)
++wlenght[truewlenght[j] - 1];
This statement is a part of a program that is not functioning correctly.
Is that maybe a reason?
The program purpose is to print a histogram of the words. This is actually an exercise 1-13 from Kernighan-Ritchie's book.
An eventual other corrections would be apprecieated. Here goes the whole code.
Thanks.
Code:
#include<stdio.h>
int main(void)
{
int c, i, n, j, m, s, ii, jj, nn, wlenght[150], truewlenght[150];
c = i = n = j = m = s = ii = jj = nn = 0;
for(s = 0; s <= 150; ++s)
{
wlenght[s] = 0;
truewlenght[s] = 0;
}
while((c = getchar()) != EOF)
{
if(c != ' ' && c != '\t' && c != '\n')
++wlenght[i];
if(c == ' ' || c == '\t' || c == '\n')
++i;
}
n = i;
for(i = 0; i <= n; ++i) /* Eliminates 0 character array members */
if(wlenght[i] > 0)
{
truewlenght[j] = wlenght[i];
++j;
}
for(i = 0; i <= n; ++i)
wlenght[i] = 0;;
m = j;
for(ii = 0, j = 0; j <= m; ++j, ++ii)
++wlenght[truewlenght[j] - 1]; /* Forms histogram inside the array wlenght */
for(jj = 0; jj < ii; ++jj)
{
putchar('|');
putchar(jj);
putchar('|');
for(nn = 1; nn <= wlenght[jj]; ++nn)
putchar('*');
}
return 0;
}