Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!mel.dit.csiro.au!yarra!melba.bby.oz.au!zvs From: zvs@bby.oz.au (Zev Sero) Newsgroups: comp.lang.c Subject: sscanf("8", "%o" &x); (was: How to validate input?) Message-ID: <1990Dec5.021519.3476@melba.bby.oz.au> Date: 5 Dec 90 02:15:19 GMT References: <2195.2754fcc2@iccgcc.decnet.ab.com> <28132@mimsy.umd.edu> <2273.275bbf88@iccgcc.decnet.ab.com> Sender: news@melba.bby.oz.au Organization: Burdett, Buckeridge and Young Ltd. Lines: 26 In-Reply-To: browns@iccgcc.decnet.ab.com's message of 4 Dec 90 20:23:51 GMT Stan = browns@iccgcc.decnet.ab.com (Stan Brown) Chris = chris@mimsy.umd.edu (Chris Torek) It is clear that strtoul("8", (char **)0, 8) succeeds and returns 0. The question is whether the *scanf conversion function can be regarded as having `succeeded'. Stan thinks that it should, quoting at length from the Standard, and Chris thinks that it should not. I haven't got the Standard, but Plauger & Brodie is supposed to be the next best thing, and I quote from page 113 (Scan Functions): Except for the conversion specifier n (which consumes no input), each conversion specification determines a pattern that one or more of the next characters in the input must match. It seems to me that this is the important bit. For a conversion to succeed, not only must the called function succeed, but it must match one or more characters. In this case, strtoul matches zero characters, so the conversion fails, x keeps whatever value it had before, and strtoul returns 0. -- Zev Sero - zvs@bby.oz.au `...And the way to do something about it is to do something about it.' - Joan Kirner (29/11/90) Brought to you by Super Global Mega Corp .com