Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Substitute for gets() Message-ID: <1989Feb8.223554.27192@utzoo.uucp> Organization: U of Toronto Zoology References: <721@hscfvax.harvard.edu> Date: Wed, 8 Feb 89 22:35:54 GMT In article <721@hscfvax.harvard.edu> xmjschm@hscfvax.harvard.edu (MJSchmelzer) writes: >Given that gets() is unsafe because it doesn't check its input, >what form of scanf() should be used? The replacement for gets() is fgets(), not scanf(). In general it is both safer and more satisfactory to read a line into a buffer with fgets() and then pick it apart by whatever means is appropriate, which might possibly include sscanf() although it isn't really satisfactory, than to try to use scanf() directly on the input. Printf() was an experiment that worked; the same cannot be said of scanf(), at least not with anywhere near the same level of enthusiasm. -- Allegedly heard aboard Mir: "A | Henry Spencer at U of Toronto Zoology toast to comrade Van Allen!!" | uunet!attcan!utzoo!henry henry@zoo.toronto.edu