aboutsummaryrefslogtreecommitdiff
path: root/ch1/1-13_word-length-histogram.c
diff options
context:
space:
mode:
authorzlg <zlg@zlg.space>2016-06-16 10:15:33 -0700
committerzlg <zlg@zlg.space>2016-06-16 10:15:33 -0700
commitf8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7 (patch)
treee37b327d7f93435e93a57427600d2b91fbb0cd87 /ch1/1-13_word-length-histogram.c
parentSolve Exercise 7-2: Format arbitrary input (diff)
downloadknr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.gz
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.bz2
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.xz
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.zip
The massive astyle sweep!
Code style should be consistent now. All future commits will be run through astyle or they will be amended.
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");
}