1.fseek
Function Prototypes:
Copy Code code as follows:
int fseek (FILE * stream, long int offset, int origin);
Parameter description: Stream, file stream pointer, offest, offset, Orgin, original (beginning position). The optional values for Orgin are Seek_set (start of File), Seek_cur (current position of the file pointer), Seek_end (end of file).
Function Description: For binary mode open stream, the new stream position is Origin + offset.
2.ftell
Function prototype: Long int ftell (FILE * stream);
Function Description: Returns the position of the stream. For the binary stream, the return value is the number of bytes from the start position of the file.
Get file size C program (FILE.CPP):
Copy Code code as follows:
#include <stdio.h>
int main ()
{
FILE * PFILE;
Long size;
PFile = fopen ("File.cpp", "RB");
if (pfile==null)
Perror ("Error opening file");
Else
{
Fseek (pFile, 0, seek_end); Move file pointer to end of file
Size=ftell (PFile); Find the number of bytes from the current file pointer to the beginning of the file
Fclose (PFile);
printf ("Size of File.cpp:%ld bytes.\n", size);
}
return 0;
}