home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / msdos / programm / 8033 < prev    next >
Encoding:
Text File  |  1992-07-23  |  1.2 KB  |  37 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!caen!destroyer!ubc-cs!unixg.ubc.ca!loon!danc
  3. From: danc@loon.geog.ubc.ca (Dan Ciarniello)
  4. Subject: Borland C++ 3.0 scanf()/gets() bug.
  5. Message-ID: <1992Jul23.181820.29495@unixg.ubc.ca>
  6. Sender: danc@loon (Dan Ciarniello)
  7. Nntp-Posting-Host: loon.geog.ubc.ca
  8. Organization: University of British Columbia, Vancouver, B.C., Canada
  9. Date: Thu, 23 Jul 1992 18:18:20 GMT
  10. Lines: 25
  11.  
  12. I've come across what I believe is a bug in Borland C++.  The following 
  13. program fragment does not work as one would expect.
  14.  
  15.         scanf("%s", var1);
  16.     gets(var2);
  17.  
  18. The scanf() statement executes correctly but gets() assigns a null string to 
  19. var2 without waiting for input from the keyboard and execution continues with
  20. the next statment.  If the scanf() is removed, gets() works as advertised.
  21. A work around that I have found is to simply include a dummy call to gets():
  22.  
  23.     scanf("%s", var1);
  24.     gets(var2);
  25.     gets(var2);
  26.  
  27. The second call to gets() works correctly.
  28.  
  29. If a subsequent call to scanf() is made, another dummy call to gets() is
  30. required for gets() to work again.
  31.  
  32. Has anyone ever come across this before (please e-mail)?
  33.  
  34. Dan.
  35.  
  36.  
  37.