home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.msdos.programmer
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!caen!destroyer!ubc-cs!unixg.ubc.ca!loon!danc
- From: danc@loon.geog.ubc.ca (Dan Ciarniello)
- Subject: Borland C++ 3.0 scanf()/gets() bug.
- Message-ID: <1992Jul23.181820.29495@unixg.ubc.ca>
- Sender: danc@loon (Dan Ciarniello)
- Nntp-Posting-Host: loon.geog.ubc.ca
- Organization: University of British Columbia, Vancouver, B.C., Canada
- Date: Thu, 23 Jul 1992 18:18:20 GMT
- Lines: 25
-
- I've come across what I believe is a bug in Borland C++. The following
- program fragment does not work as one would expect.
-
- scanf("%s", var1);
- gets(var2);
-
- The scanf() statement executes correctly but gets() assigns a null string to
- var2 without waiting for input from the keyboard and execution continues with
- the next statment. If the scanf() is removed, gets() works as advertised.
- A work around that I have found is to simply include a dummy call to gets():
-
- scanf("%s", var1);
- gets(var2);
- gets(var2);
-
- The second call to gets() works correctly.
-
- If a subsequent call to scanf() is made, another dummy call to gets() is
- required for gets() to work again.
-
- Has anyone ever come across this before (please e-mail)?
-
- Dan.
-
-
-