Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!hal!ncoast!allbery From: allbery@ncoast.ORG (Brandon S. Allbery) Newsgroups: comp.unix.wizards Subject: Re: Unix problem or C problem? Message-ID: <13397@ncoast.ORG> Date: 19 Feb 89 16:58:25 GMT References: <18366@adm.BRL.MIL> Reply-To: allbery@ncoast.UUCP (Brandon S. Allbery) Followup-To: comp.unix.wizards Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 26 As quoted from <18366@adm.BRL.MIL> by rbj@nav.icst.nbs.gov (Nilbert T Bignum): +--------------- | ? 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. +--------------- Using scanf() for interactive input has another wart: if the (l)user doesn't enter exactly the number of data items requested, s/he won't be prompted properly for further input. And it's (almost) impossible to catch malformed data files in the non-interactive case. ++Brandon -- Brandon S. Allbery, moderator of comp.sources.misc allbery@ncoast.org uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu Send comp.sources.misc submissions to comp-sources-misc@ NCoast Public Access UN*X - (216) 781-6201, 300/1200/2400 baud, login: makeuser