Newsgroups: comp.lang.c Path: utzoo!utgpu!watserv1!watmath!datangua From: datangua@watmath.waterloo.edu (David Tanguay) Subject: Re: Trouble at EOF Message-ID: <1991Jun17.120927.3802@watmath.waterloo.edu> Organization: University of Waterloo References: <12847@pucc.Princeton.EDU> <4739@inews.intel.com> Date: Mon, 17 Jun 1991 12:09:27 GMT Lines: 21 In article <4739@inews.intel.com> bhoughto@pima.intel.com (Blair P. Houghton) writes: > while ( fgets(s, sizeof s, stream) ) > /* not eof */ > process(s); > > /* reached iff eof */ > if ( strlen(s) != 0 ) { > /* there's something left to process */ > if ( s[strlen(s) - 1] != '\n' ) > /* it has no newline */ > strcat(s,"\n"); > process(s); > } Huh? 4.9.7.2: "If end-of-file is encountered and no characters have been read into the array, the contents of the array remain unchanged and a null pointer is returned." fgets does not return NULL for eof when there are characters read, so (barring I/O errors) the above code will process the last "line" twice. -- David Tanguay datanguay@watmath.waterloo.edu Thinkage, Ltd.