Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between stdin and STDIN_FILENO?

Tags:

c

What is the practical difference, if any, between stdin and STDIN_FILENO in C?

like image 654
user1212697 Avatar asked Feb 27 '13 02:02

user1212697


People also ask

Where is STDIN_FILENO defined?

On program startup, the integer file descriptors associated with the streams stdin, stdout, and stderr are 0, 1, and 2, respectively. The preprocessor symbols STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO are defined with these values in <unistd.

What is the value of STDIN_FILENO?

STDIN_FILENO. Standard input value, stdin. Its value is 0.

What does stdin mean?

The standard input device, also referred to as stdin , is the device from which input to the system is taken. Typically this is the keyboard, but you can specify that input is to come from a serial port or a disk file, for example.

What type of file is stdin?

Short for standard input, stdin is an input stream where data is sent to and read by a program. It is a file descriptor in Unix-like operating systems, and programming languages, such as C, Perl, and Java.


2 Answers

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.

like image 75
Michael Avatar answered Oct 12 '22 12:10

Michael


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.

like image 41
squiguy Avatar answered Oct 12 '22 13:10

squiguy