atari email archive

a collection of messages sent at Atari from 1983 to 1992.

to "C" hackers

(1 / 1)


WARNING: A lesson which might be less painful for you if you learn it here:

    FILE *outfil;
    char c;		/* output char */
    int err;		/* putc() result code */
	.
	.
	.
    if ((err = putc(c, outfil)) == EOF) {
	perror(" Output error in putc() - disk full? ");
	return (ERROR);
    }
	.
	.
	.

This will screw up on binary files when (c = 0xFF) is output, because putc()
will return the sign extended argument, which will be EOF (-1) rather than 0xFF.
You need to either check ferr(outfil) on EOF, or call putc(c & 0xFF, outfil) to
suppress the sign extension.  It ain't like getc()!!

OLD NEWS:  Also, since getc and putc() are #define macros on some systems
(including UNIX), don't make calls like putc(*cp++, outfil), since the side
effect will blow up in your face.  Use fgetc() and fputc(), which make proper
subroutine calls instead. 
Message 1 of 1

Oct 01, 1985