C common file operations

Some common types of file operations

"R" is opened for reading text files (the error does not exist)

"W" is a text file is opened for writing (if there is new, and vice versa, from the start of file writing, the original contents are overwritten)

"A" is added after the data file to open a text file (if there is new; the other hand, in the original file is appended)

"R +" open text file to read and write (read, start from scratch; when writing data, the new data covers only the space occupied by the same thereafter)

"Wb" open binary file for writing

"Rb" binary file is opened for reading

"Ab" is added after the data file to open a binary file

"Rb +" for the reading and writing binary file open, but then the subsequent reading and writing, reading and writing starting position may be provided by a function of the position

"W +" First create a new file, write, and then you can start from scratch read (if the file exists, the original content will disappear)

"A +" function and "a" the same; only add new data after the end of the file to be read from the beginning

"Wb +" function "w +" the same. When a subsequent read only, read and write starting position can be provided by a function of the position

"Ab +" function and "a +" the same; only the tail after adding new data file, the read start position may be provided by the function of the position

 

Some common file operations

1, read the file

 

 

 

 

char * fgets(char *s, int n, FILE *stream);

s: character pointer, points to the address data stored in the read buffer

n: n-1 characters read from the stream

stream: the stream read points

 

2, the line that reads

3, write

int fputs(const char *str, FILE *stream);

str: This is an array containing a null terminated sequence of characters to be written

stream: FILE pointer to an object, the object identifying FILE stream to be written into the string

 

Old nine school community members produced

Author: Zero_ ball

Guess you like

Origin www.cnblogs.com/ljxt/p/11579584.html