Hello,
I just started delving into C and programming in general a few days ago with K&R and I'm struggling with exercise 1.13 (The Histogram). A bit too early to struggle eh? :P
Instead of horizontal asterisks I only get '0' which is the printlen[] initialization. I'm guessing I can't add characters the way I imagined?
This is what I've come up with so far and it compiles fine as is. Not sure if my thought process is correct here. I hope I'm on the right path at least.
What I am guessing is going wrong is that it's not adding the '*' to the initialization of printlen[] in this line:Code:#include <stdio.h> int main(void) { int printlen[10]; int clen = 0; int c = 0; for(clen = 0; clen <= 10; ++clen) /* Initialize printlen array */ printlen[clen] = 0; while ((c = getchar()) != EOF) /* Loop until EOF */ { if ( c != ' ' || c != '\n' || c != '\t') /* Check start and end of word */ ++clen; printlen[clen] = '*' + printlen[clen]; /* Count '*' */ } printf("Length\n"); for(clen = 0; clen < 10; ++clen) printf(" %d\t %c\n", clen, printlen[clen]); printf(" >10\t %c\n", printlen[clen]); return 0; }
printlen[clen] = '*' + printlen[clen];
If I can get passed that I should be able to fix all the other 'bugs' in here.
Thanks for any advice on the matter.
Yannis