# Include <stdio. h> FILE * pFile = fopen (, (pFile = NULL) perror (fseek (pFile, size = pFile = printf (}
First, use fseek (pfile, 0, SEEK_END) to move the current position of the file to the end of the file, and then call the ftell () function to obtain the current position relative to the first position of the file, this displacement value is equal to the number of bytes contained in the file. In this way, the file size is obtained!
Fseek (relocate the file pointer on the Stream)
Int fseek (FILE * stream, long offset, int fromwhere );
Function Description: The first parameter stream is the file pointer, the second parameter offset is the offset, the integer indicates the positive offset, and the negative value indicates the negative offset. The third parameter fromwhere sets the offset starting from the file, possible values: SEEK_CUR (current location), SEEK_END (end of the file), or SEEK_SET (start of the file). SEEK_SET, SEEK_CUR, and SEEK_END are values 0, 1 and 2 in sequence.
For example:
Fseek (fp, 100L, 0); move the fp pointer to the first 100 bytes from the file;
Return Value: success. 0 is returned. Otherwise, other values are returned.
Ftell (returns the current file location)
Long ftell (FILE * stream)
Function Description: obtains the number of offset bytes between the current position of the file pointer and the beginning of the file.