open and fopen function [duplicate]
Possible Duplicate:
C fopen vs op开发者_Go百科en
What is the difference between open() and fopen() in C language?
One is part of the standard c library (fopen
) so you can expect it to be present on all hosted c compiler setups. This function returns a FILE*
which can be operated on by the functions in <stdio.h>
.
The other (open
) is a system call/function not specified by the c standard (however, i believe it is part of the POSIX standard) and therefore only guaranteed to exist on select platforms which claim to support it. This returns an int
which represents a file, this can be operated on using read
/write
and other similar functions.
open()
is a standardised system call provided by a POSIX compliant operating system (most POSIX-like operating systems also have the open()
system call). fopen()
is a C library function provided by the C implementation and/or runtime library.
fopen()
allows for buffered and/or formatted input/output, whereas open()
is generally used for more straightforward IO. It is possible for the fopen()
function to be implemented using the open()
system call.
As others said open() is a system call through POSIX standard, mostly supported by UNIX family of operating systems. It returns 'int' indicating the file descriptor being opened.
While on the other hand fopen() is provided by C-library and it returns a FILE* pointing to the file being opened.
精彩评论