C problems

Rahul Dhesi dhesi at bsu-cs.bsu.edu
Wed May 31 14:51:08 AEST 1989


In article <365 at xdos.UUCP> doug at xdos.UUCP (Doug Merritt) writes:
>		putc(c, fp2);
and
>	fclose(fp1);

May I respectfully suggest error-checking:

     if (putc(c, fp2) == EOF)
	... handle error ...

And yes, even fclose!

     if (fclose(fp1) == EOF)
	... handle error ...

It seems like overkill, but not detecting a full device is a *very*
common bug in C programs.  (However, a possible optimization is to call
ferror() just once before the output stream is closed instead of
testing the value from putc all the time.)
-- 
Rahul Dhesi <dhesi at bsu-cs.bsu.edu>
UUCP:    ...!{iuvax,pur-ee}!bsu-cs!dhesi
Career change search is on -- ask me for my resume



More information about the Comp.lang.c mailing list