Author: Alessandro Scotti
Date: 02:27:46 08/30/04
Go up one level in this thread
On August 29, 2004 at 19:59:40, Robert Hyatt wrote: >On August 29, 2004 at 17:44:16, Alessandro Scotti wrote: > >>On August 29, 2004 at 12:04:47, Uri Blass wrote: >> >>>2)Is it safe to use fgets()? >>>I remember that it is not safe to use gets() and I think that for the same >>>reason it is not safe to use fgets() >> >>fgets() is safe. The difference with gets() is that the latter doesn't take the >>buffer size as a parameter, so it can overflow your buffer. Other minor >>difference s are that gets() removes end of line characters from the string, >>while fgets() leaves them there, and also that gets() can only read from stdin. > > >It isn't safe from the point of view of being able to ask "has anything been >typed on the keyboard" because fgets() uses library buffering which hides input >from the operating system's "is there input" query. I assumed safe referred to security here. For the rest, it's not too bad to get input only after "Enter" is pressed, I've recently switched to this line-oriented mode and so far I'm quite happy with it as it's quite portable and simple to code.
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.