Jump to: navigation, search

My solution to ex 1-16 has a bug. This was reported to me by Marnix Kaart. The bug manifests itself when reading a line precisely MAXLINE characters in length (including the newline), and the actual bug is because of a typo in getline.

Rather than submit a fixed version myself, I am encouraging him to do so (as he is a relatively new C programmer).

Bug in program?

It seems that there is a bug (or, at least, buggy behavior) in the programs in section 1.9. If you feed the program a file consisting entirely of lines whose lengths exceed MAXLINE characters, a newline won't be appended to the char array. So all of these monstrously large lines will be printed on a single line. Large files whose entire contents are on a single line can cause text editors to choke (among other problems). So it seems that there should be something like

if (len >= MAXLINE)
    putchar('\n');

in the main function to avoid this problem.

Personal tools