Unix problem or C problem?

Nilbert T Bignum rbj at nav.icst.nbs.gov
Tue Feb 14 02:59:19 AEST 1989


? As an aside, I generally avoid testing scanf() values against EOF. scanf()
? returns the number of successful assignments (1 in this case), so you may
? be a lot safer saying: ...

I agree. In fact, I would avoid testing the return value of scanf or
fscanf against *anything*. Don't use them at all. Use fgets followed
by sscanf. If you don't like the input on a particular line, it is
easier to throw it away by doing another fgets than by constructing
a scanf expression to read `any string terminated by newline but only
up to this many characters into that junk buffer over there'. On another
point, you may want to rescan the input somehow.

	Nilbert T Bignum <rbj at nav.icst.nbs.gov>
	NTSI: Never Twice the Same Institute



More information about the Comp.unix.wizards mailing list