What is the difference between stdin and STDIN_FILENO?
Solution 1:
The interface. Like everyone else has said, stdin
is a FILE *
as defined by the standard c library. You can use some of the higher level interfaces like fread
, fwrite
, and fprintf
. On the other hand, STDIN_FILENO
is just a file descriptor (almost certainly 0). This uses a slight lower level interface through the likes of read
and write
.
Solution 2:
stdin
is a default FILE pointer used to get input from none other than standard in.
STDIN_FILENO
is the default standard input file descriptor number which is 0
. It is essentially a defined directive for general use.