126k views
3 votes
What function do you use to get the file descriptor number from a file stream?

a) getfd()
b) fileno()
c) filedescriptor()
d) streamfd()

User Peacemaker
by
8.9k points

1 Answer

6 votes

Final answer:

The function used to obtain a file descriptor number from a file stream is fileno(), which is used in C programming.

Step-by-step explanation:

The function used to get the file descriptor number from a file stream in C is fileno(). This function is part of the standard C library and takes a FILE* pointer (which represents an open file stream) as an argument and returns the associated file descriptor as an int. If an error occurs, fileno() typically returns -1, and an application can check errno for the error code to determine the cause of the error.