Hi, all. I don't so much have a problem. My code works (or at least, it does in all tests I've ran so far), but as I'm still working on some of the examples in K&R, I'm just looking for some comments. Criticisms especially. If I've done something dumb, I want to know about it. Any feedback is helpful

.
Please note that I'm not using pointers, functions, or anything that has not been introduced yet at this time in the book... trying to play fair.
Anywhoo... here's the assignment, from the K&R text.
Quote:
|
Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging.
|
And here's my program.
/* K&R
* Chapter 1
* Exercise 1-13
* Prints a histogram of word sizes
*/
#include <stdio.h>
#define MAXSIZE 10 /* Maximum word size */
int main(void)
{
int arr[MAXSIZE+1]; /* 10 sizes of words, plus a >MAXSIZE field */
int i, j, nc, c; /* Loop counters, number of characters, character */
int highest = 0; /* Used to get the highest value in arr[] */
/* initialize arr[] to 0*/
for (i = 0; i <= MAXSIZE; ++i)
arr[i] = 0;
nc = 0;
while ((c = getchar()) != EOF) {
++nc; /* Here we increment with each character until we hit a blank... */
if (c == ' ' || c == '\n' || c == '\t' || c == EOF){
--nc; /* ...then drop the blank */
if (nc <= MAXSIZE) {
arr[nc-1]++;
nc = 0;
} else if (nc > MAXSIZE) {
arr[MAXSIZE]++;
nc = 0;
}
}
}
/* Let's see what the highest number in arr[] is */
for (i = 0; i <= MAXSIZE; ++i) {
if (arr[i] > highest)
highest = arr[i];
}
/*Now let's do a vertical histogram */
while (highest > 0) {
printf("\t%3d: ", highest);
for (i = 0; i <= MAXSIZE; ++i) {
if (highest > arr[i])
printf(" ");
else
printf(" | ");
}
printf("\n");
highest--;
}
/* And now, the footer */
printf("\t --------------------------------------------------------\n\t ");
for(i = 0; i <= MAXSIZE; ++i) {
if (i < MAXSIZE)
printf(" %d ", i+1);
else
printf(">%d ", MAXSIZE);
}
return 0;
}
Thanks,
Phil