C语言文件操作总结
File manipulation function
File on / off
FILE, *infile, =fopen ("ride? in〃,〃W〃);
Fclose (inf订e);
File read:
Fgetc:
Format: int fgetc (FILE ^stream);
Reads a character from the file pointing to the file pointer stream?
The return value of this function is a byte that returns the read. Returns EOF (-1) if it is read at the end of the file or when the error is read.
Fgets:
The prototype is char *f gets (char, *s, int, N, FILE, * stream);
Parameter:
*s: character pointer to the data address that will be stored.
N: integer data, which reads n - 1 characters from the stream.
^stream: pointer data, the stream to read.
Function:
Read nT characters from the file pointer stream, save in the space where s is the starting address, until you have completed a row, and if successful, return the pointer to s, or else return NULL.
Fscanf:
Function name: fscanf
Function: performs formatted input from a stream, fscanf ends with spaces and line breaks, and ends with spaces? This is different from fgets, where fgets encounters spaces that do not end.
Usage: int, fscanf (FILE, ^stream, char, ^format,
[argument ,???);
Int fscanf (file pointer, format string, input list);
Example:fscanf (FP,%s%d%lf, a, &b, &c)
Return value: integer, value equal to the number of [argument??? _
Fread:
Function prototypes: size_t, FREAD (void, ^buffer, size_t, size, size_t, count, FILE, ^stream);
Function: read data from a file stream, read count elements, each element size bytes? If the call succeeds, return count?? If the call is successful, the actual read size*count bytes are read
Parameter:
Buffer: is used to receive data memory addresses, at least size*count bytes in size
Size: the size of a single element, in bytes
The number of count: elements, each of which is size bytes? Stream: input stream
Return value: the number of elements actually read. If the return value is not the same as count (not count*size), the end or error of the file may occur
Gets the error information from f err or and f