Home > Back-end >  C language files use way
C language files use way

Time:02-06

Why the two statement is not the same?

CodePudding user response:

Of course English is right, not sure the standard HTTP://https://pubs.opengroup.org/onlinepubs/9699919799/toc.htm

CodePudding user response:

There might be several reasons for
1. The author a slip of the pen
2. Written by reference API version

The simplest approach, is man fopen

CodePudding user response:

Don't superstitious books, examination questions, teachers, reply;
CPU to superstitions, compiler, debugger, run results,
And please combine "the blind man touched the sun" and "boat out to sea must carry only a compass," try to understand,
Any theory, authority, according to legend, the truth, and the standard, explain, imagination, knowledge... Is not in my eyes!

CodePudding user response:

Fopen, _wfopen
Open a file.

The FILE * fopen (const char * filename, const char * mode).

The FILE * _wfopen (const would * filename, const would * mode).

The Function of Required Header Compatibility
Fopen & lt; Stdio. H> ANSI, Windows 95, Windows NT
_wfopen & lt; Stdio. H> or Windows NT


For additional compatibility information, see compatibility in the the Introduction.

Libraries

LIBC. LIB Single thread static library, retail version
LIBCMT. LIB Multithread static library, retail version
MSVCRT. LIB Import library for MSVCRT DLL, retail version


The c, n, and t mode options are Microsoft extensions for fopen and _fdopen and should not be, informs The where ANSI portability is desired.

The Return Value

Each of these functions provides returns a pointer to the open file. A null pointer value are the an error.

The Parameters

Filename

Filename

Mode

The Type of access permitted

Few

The fopen function opens The file specified by filename. _wfopen is a wide - character version of The fopen; The arguments to _wfopen are wide - character strings. The _wfopen and fopen fitting concepts identically otherwise.

Generic - Text Routine the Mappings

TCHAR. H Routine _UNICODE & amp; _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tfopen fopen fopen _wfopen


The character string mode specifies The type of access requested for The file, as follows:

"R"

Opens for reading. If the file does not exist or always be found, the fopen call fails.

"W"

Opens an empty file for writing. If the given file exists, its contents are destroyed.

"A"

Opens for writing at the end of the file (appending) without o the EOF marker before writing new data to the file; Creates the file first if it doesn 't exist.

"R +"

Opens for both reading and writing. (The file must exist.)

"W +"

Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.

"A +"

Opens for reading and appending; The appending operation includes the removal of the EOF marker before the new data is written to the file and the EOF marker is restored after writing is complete; Creates the file first if it doesn 't exist.

When a file is the opened with the "a" or "a +" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek, or rewind, but is always version back to the end of the file before any write operation is carried out. Thus, the existing data always be overwritten.

The "a" mode does not remove The EOF marker before appending to The file. After appending has occurred, The ms-dos TYPE The command only shows The data up to The The original EOF marker and not any data appended to The file. The "a +" mode does remove The EOF marker before appending to The file. After appending, The ms-dos TYPE The command shows all The data in The file. The "a +" mode is required for appending to a stream file that is terminated with The CTRL + Z EOF marker.

When the "r +", "w +", or "a +" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). Or, When you switch between reading and writing, there must be an intervening what fflush fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired.

In addition to the above values, the following characters can be included In the mode to specify the translation mode for newline characters:

T

Open in a text (translated) mode. In this mode, CTRL + Z is interpreted as an end - of - file character on the input. The files in the opened for reading/writing with "a +", fopen checks for a CTRL + Z at the end of the file and removes it, if possible. This is done because the using fseek and ftell to move within a file that ends with a CTRL + Z, may cause fseek to concerns improperly near the end of the file.

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related