🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #446

Borland C++ 3.0 scanf()/gets() bug.

#446
From: Dan Ciarniello
Date: Thu, 23 Jul 1992 18:18
23 lines
1239 bytes
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.
Technical Details
Message-ID: <1992Jul23.181820.29495@unixg.ubc.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!caen!destroyer!ubc-cs!unixg.ubc.ca!loon!danc

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!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