aboutsummaryrefslogtreecommitdiff
path: root/ch1/1-13_word-length-histogram.c
diff options
context:
space:
mode:
Diffstat (limited to 'ch1/1-13_word-length-histogram.c')
-rw-r--r--ch1/1-13_word-length-histogram.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/ch1/1-13_word-length-histogram.c b/ch1/1-13_word-length-histogram.c
index b557417..a2ee173 100644
--- a/ch1/1-13_word-length-histogram.c
+++ b/ch1/1-13_word-length-histogram.c
@@ -33,19 +33,17 @@ int main(void) {
* lengths = an array that keeps track of how often words up to x chars long
* occur.
*/
-
int state, ltrs, wrds, lines, wlen, i, j;
int lengths[MAXWLENGTH];
for (i = 0; i <= MAXWLENGTH; ++i) {
lengths[i] = 0;
}
-
ltrs = wrds = wlen = 0;
lines = 1;
state = OUT;
- // Capture input until it ends
+ /* Capture input until it ends */
while ((i = getchar()) != EOF) {
- // If it's whitespace, we've exited a word
+ /* If it's whitespace, we've exited a word */
if (i == '\n' || i == ' ' || i == '\t') {
if (state == IN) {
++wrds; // ...and should increase the count.
@@ -54,7 +52,7 @@ int main(void) {
if (wlen <= MAXWLENGTH) {
++lengths[wlen];
}
- // Reset our word length now.
+ /* Reset our word length now. */
wlen = 0;
}
/* If it's a new line, we're still out of a word but need to increment the
@@ -70,13 +68,12 @@ int main(void) {
/* Everything that's input counts as a letter. */
++ltrs;
}
-
printf("\nWORD LENGTH FREQUENCY\n ");
for (i = 5; i < 80; i += 5) {
printf(" %2d", i);
}
-
- printf("\n"); // End the chart heading.
+ /* End the chart heading. */
+ printf("\n");
j = MINWLENGTH;
while (j <= MAXWLENGTH) {
i = lengths[j];
@@ -84,7 +81,7 @@ int main(void) {
printf("%2d | ", j);
while (i > 0) {
printf("#");
- i = i-1;
+ i = i - 1;
}
printf("\n");
}