I was reading a book from 1997 that teaches how to program in C, and it always uses the word “usually” when specifying that functions like scanf take input from the keyboard. Because of this, I'm curious as to if functions like scanf can take input from other devices, or if it used to.
CodePudding user response:
Because of this, I'm curious as to if functions like scanf can take input from other devices, or if it used to.
scanf
takes input from the program's standard input. What this is connected to is a matter of the operating environment and the way the program is launched. (Look up "I/O redirection"). It is not unusual for a program's standard input to be connected to a file on disk or to the output of another program. It sometimes is connected to a socket. More rarely, it is connected to a serial port, or to a null device, or a source of zeroes or random bytes.
Historically, it might have been connected to a card or paper tape reader.
In principle, it can be connected to any device that produces data -- a mouse, for example -- but just because something is possible doesn't make it useful.