Why is there no dscanf function for reading from file descriptors?
We have fprintf, sprintf and dprintf for printing but for scanning there is only fscanf and sscanf.
It is not possible to write dscanf
.
The scanf family requires that the stream is buffered, or else that it is capable of putting back a character that was read. POSIX file descriptors are neither.
Consider this stream
1234xyz
How would you scan a number off it? You cannot read it byte by byte and stop just before x
. That would require clairvoyance. You also cannot read x
and decide you don't need it, because you cannot put it back.
Because the printf
and scanf
family of functions is part of the C language, the functions handling file descriptors are not. Instead they are part of the operating system API (on POSIX platforms like Linux or OSX, other platforms emulate these system calls).
And the dprintf
function is not a standard C function, it's an extension. From this printf
(and family) manual page:
The
dprintf()
andvdprintf()
functions were originally GNU extensions that were later standardized in POSIX.1-2008.
That there's no dscanf
function is probably just an oversight from those who made the original dprintf
extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With