I've been struggling with exercise 1-13 from the K & R book for weeks now. The task is to create a histogram that displays the lengths of words from the input. I've attempted to code the solution multiple times—at least ten—and I keep getting the logic wrong. I managed to store the lengths of the words in an array, but I can't seem to figure out how to convert that data into a histogram for printing. Out of frustration, I even asked Chat GPT for help, and it fixed my code, but I still feel stuck. I've also worked through a lot of exercises in Prata and King, hoping that would prepare me, but it didn't. I'm feeling discouraged and questioning whether I should continue, especially if I'm struggling with these exercises. If I can't tackle these, how will I manage more complex problems in my future projects?
2 Answers
Honestly, I wouldn't say the K & R exercises are too tough. They're more moderate in difficulty. If you have a grasp on computer architecture, they should be manageable. But remember, this book was written for those who have some programming experience already, especially in languages like Fortran, COBOL, or even PL/I.
The early exercises are usually not that hard. Can you tell me what specifically tripped you up in your logic?
I had trouble figuring out how to convert the stored word lengths into a histogram. I wanted to have just one column for words of the same length, rather than N columns if the same length appeared multiple times.