Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!mips!pacbell.com!decwrl!shelby!msi.umn.edu!cs.umn.edu!cybrspc!roy From: roy%cybrspc@cs.umn.edu (Roy M. Silvernail) Newsgroups: comp.lang.c Subject: Re: What's so bad about scanf anyway??? Message-ID: Date: 11 Nov 90 07:49:54 GMT References: <16582@netcom.UUCP> Organization: Villa CyberSpace, Minneapolis, MN Lines: 19 avery@netcom.UUCP (Avery Colter) writes: > In the self-teaching course I have here, scanf is the most often used > input function. I don't see gets used much at all. > > And indeed, gets only seems of much advantage when you want to take in > a whole line into one string. The problem with scanf() is that it can behave unpredictably when you give it badly formatted input. It's better, IMHO, to gets() a whole line, check its validity and _then_ sscanf() it into the target variables. (no need for strtol() or similar, since sscanf() looks at the validated string just as scanf() would have looked at the original input) It just makes things more bullet-resistant. -- Roy M. Silvernail |+| roy%cybrspc@cs.umn.edu |+| #define opinions ALL_MINE; main(){float x=1;x=x/50;printf("It's only $%.2f, but it's my $%.2f!\n",x,x);} "This is cyberspace." -- Peter da Silva :--: "...and I like it here!" -- me