What's so bad about scanf anyway???

Richard Caley rjc at uk.ac.ed.cstr
Tue Nov 13 23:28:22 AEST 1990


In article <1990Nov12.112032.22979 at diku.dk> kimcm at diku.dk (Kim Christian Madsen) writes:

    rjc at uk.ac.ed.cstr (Richard Caley) writes:

    >In article <VXogs2w163w at cybrspc> roy%cybrspc at cs.umn.edu (Roy M. Silvernail) writes:

    >    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.

    >Maybe it was just a typo, but repeat after me

    >	`GETS is EVIL'

    >This has been un unpayed anouncement by paranoids anonymous.

    gets can get you into a lot of trouble if used for in a non-controlled
    manner, e.g. for user input. Then you be better off by using fgets or
    reading char-by-char with getchar() or family. But using scanf() for user
    input is asking for trouble!


Sorry for being confusing, I wasn't defending scanf, I was just
pointing out the fact that gets is never useful.

--
rjc at uk.ac.ed.cstr		_O_
				 |<



More information about the Comp.lang.c mailing list