home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!agate!stanford.edu!kronos.arc.nasa.gov!butch!netcomsv!netcomsv!ulogic!hartman
- From: hartman@ulogic.UUCP (Richard M. Hartman)
- Newsgroups: comp.lang.c
- Subject: Re: ** Ack! Help again! **
- Message-ID: <841@ulogic.UUCP>
- Date: 11 Jan 93 17:18:34 GMT
- References: <kaNTwB1w165w@tradent.wimsey.bc.ca> <dschmitz.726261452@pv0321.vincent.iastate.edu>
- Organization: negligable
- Lines: 64
-
- In article <dschmitz.726261452@pv0321.vincent.iastate.edu> dschmitz@iastate.edu (Daniel C Schmitz) writes:
- >In <kaNTwB1w165w@tradent.wimsey.bc.ca> lord@tradent.wimsey.bc.ca (Jason Cooper) writes:
- >
- >>time I use scanf or gets, and I ask for more than one input of a string
- >>in a row, like this:
- >>gets(string1)
- >>gets(string2)
- >>or however that works (the point being they are seperate lines), C will
- >>skip some of the inputs for apparently no reason at all.
- >
- >I have often had problems with scanf followed by a gets. The first gets
- >that follows any series scanf's always returns an empty string.
- >A hack that has worked for me on some systems is to put a dummy gets between
- >scanf's and gets's.
- >
- >scanf(...)
- >scanf(...)
- >gets(..) /* this is a dummy, to fix problems that I've experienced */
- >get(...) /* legitimate gets, use the results */
- >scanf(...)
- >gets(...) /* dummy */
- >gets(...) /* useful value */
- >
- >dschmitz
- >dschmitz@iastate.edu
-
- There should be no need for such a hack.
- In your scanf(), does the format string contain a "\n"?
- Try this:
-
- /* test.c */
- #include <stdio.h>
- main()
- {
- int i; char buf[81];
-
- fflush(stdin);
- scanf("%d", &i);
- gets(buf);
- printf("[%d], [%s]\n", i, buf);
-
- fflush(stdin);
- scanf("%d\n", &i);
- gets(buf);
- printf("[%d], [%s]\n", i, buf);
- }
-
- log of run:
-
- $ ./test
- 23
- [23], []
- 132
- fsdljk
- [132], [fsdljk]
- $
-
-
- -Richard Hartman
- hartman@ulogic.COM
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- "There are no problems, only opportunities!"
- "What we have here is an insurmountable opportunity..."
-