open and fopen function [duplicate]

2020-08-10 07:29发布

Possible Duplicate:
C fopen vs open

What is the difference between open() and fopen() in C language?

标签: c
3条回答
Juvenile、少年°
2楼-- · 2020-08-10 07:56

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.

查看更多
迷人小祖宗
3楼-- · 2020-08-10 08:15

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.

查看更多
狗以群分
4楼-- · 2020-08-10 08:18

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.

查看更多
登录 后发表回答