Path: utzoo!attcan!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.lang.c Subject: Re: Curious Behaviour of "sscanf" Summary: That's the way it works Keywords: sscanf, c compilers. Message-ID: <307@sdrc.UUCP> Date: 19 Jun 88 19:43:58 GMT References: <236@c10sd3.StPaul.NCR.COM> Organization: Structural Dynamics Research Corp., Cincinnati Lines: 24 In article <236@c10sd3.StPaul.NCR.COM>, anderson@c10sd3.StPaul.NCR.COM (Joel Anderson) writes: > On a call to sscanf as follows: > if (sscanf(argv[3],"X=(%d,%d)",&y,&z) == 2) > and an input string where argv[3] is as follows: > "X=(1,4" > (not including the double quotes), why does sscanf in this case evaluate to > true? Sscanf matches the number of arguments but does not continue parsing > the control string (i.e. true even though the closing paren is missing)? > > Perhaps this is correct - is it? Yep, that's the way scanf works. The problem is not that scanf doesn't continue parsing the control string -- it does -- the problem is that it doesn't have any way to let you know there was a problem. The definition of scanf states that it returns the number of items successfully converted; since it successfully converted 2 arguments, that's what it returned and that's what you were expecting. ---- Larry Jones UUCP: ...!sdrc!scjones SDRC AT&T: (513) 576-2070 2000 Eastman Dr. BIX: ltl Milford, OH 45150 "When all else fails, read the directions."