Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Pascal taught a generation of coders that you test for end-of-file before trying to read any data from the stream.

When they hit C, they wrote code around fgets that processes the last line twice:

  while (!feof(instream)) {
    fgets(linebuf, sizeof linebuf, instream);
    process_line(linebuf);
  }
Or processes the EOF value from getc as a character:

  while (!feof(instream)) {
    char ch = getc(instream);
    switch (ch) ...
  }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: