In defense of scanf() (Re: Re^2: scanf(..))

Dave Hammond daveh at marob.masa.com
Sat Jun 17 22:18:02 AEST 1989


In article <824 at cbnewsl.ATT.COM> mpl at cbnewsl.ATT.COM (michael.p.lindner) writes:
>> > When filtering tabular data from files, ....
>>
>in the middle of a strtok of another string it trashes its state information
>on the first string (a little known feature), which can cause extremely
>elusive bugs.

Not only that, since it delimits the returned token by replacing the
terminating blank with a null, you are forced to work with a copy
of the input line, if for some reason the complete line must survive
the call to strtok().

I prefer using strpbrk(line, "\s\t\n") and either copying, or just
peeking at the token, whichever is required.

--
Dave Hammond
daveh at marob.masa.com



More information about the Comp.lang.c mailing list