Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!husc6!hscfvax!xmjschm From: xmjschm@hscfvax.harvard.edu (MJSchmelzer) Newsgroups: comp.lang.c Subject: Substitute for gets() Message-ID: <721@hscfvax.harvard.edu> Date: 8 Feb 89 05:00:23 GMT Organization: Health Sciences Computing Facility, Harvard University Lines: 30 Given that gets() is unsafe because it doesn't check its input, what form of scanf() should be used? The problem I'm having is this: scanf("%s", buffer); where buffer is char[255] and the scanf statement is in a loop, the \n gets passed to the next scanf call. Another problem is if I enter, say: foo bar to this scanf-in-a-loop, it cycles through the stdin buffer twice to yield: foo bar I know I'm not saying this very well, sorry. But I figure this is a pretty basic dilemma that most folks have encountered. I mean, gets() in such a loop does just fine, ie it would return "foo bar", but I have yet to kludge up a functionally equivalent scanf(). Does this mean gets() is indispensable ? Thanks for any help/insights. -- ============== xmjschm@harvspha.BITNET ============= Mike Schmelzer xmjschm@hscfvax.harvard.edu Quotes are stupid. =====================================================