Problems with scanf()

Bill Poser poser at csli.Stanford.EDU
Sun Oct 28 07:26:29 AEST 1990


I don't see why it is necessary to worry about scanf(). It is safe to use
directly only when you are quite sure of the input format, which is not
very often. But you can use its parsing facilities safely by reading
input using a safe getline function (I often use one that strips
comments and allows quoting of newlines in place of one that merely
counts input characters to prevent overflowing the buffer) and then
using sscanf(). Except for one-shot programs I suggest avoiding fscanf()
altogether and using sscanf plus a safe input function.



More information about the Comp.lang.c mailing list