Q:

histogram of length of words debug

#include <stdio.h>

int main (void) { 
FILE *fp; 
fp = fopen("test.txt", "r"); 

int char_counter, i, c; 
int word_length[12]; 

char_counter = 0; 
for (i = 0; i <= 12; i++) {
    word_length[i] = 0; 
}

while ((c = getc(fp)) ! = EOF) {
    if (c == '\n' || c == '\t' || c == ' ')
    {
        word_length[char_counter] = word_length[char_counter] + 1;
        char_counter = 0; 
    }
    else {
        ++char_counter; 
    }
}

for (i = 0; i <= 12; i++) {
    printf("%d  %d\n", i, word_length[i]); 
}

return 0; 
}

test.txt: 

blahblahblah blahblah blah bla bl b b

Output: 
0   0
1   1
2   1
3   1
4   1
5   0
6   0
7   0
8   1
9   0
10  0
11  0
12  -1 <-- ??  

Expected output looks the same but there should be a 1 at row 12 and not -1.  I don't really  understand how I got a negative number.   

A:

The code 
int word_length[12];

means that you have 12 items in the list numbered 0 .. 11
The trying to access item 12 you get undefined behaviour.