C language learned by suffering
C language learned by suffering
How to get file size
I would like to know the file size, what is the function for that?
There is no function in C to know the file size.
To find out the file size, open the file and then move the file pointer to find it.
fpos_t is a variable meaning the size of the data, which is actually an unsigned integer; changing it to an int is not much of a problem.
Also, the above process changes the file pointer, i.e., the current read position, so the following is used to change it back.
To find out the file size, open the file and then move the file pointer to find it.
sum.c
fpos_t GetFileSize(const char* FileName[])
{
fpos_t fsize = 0;
FILE* fp = fopen(FileName, "rb");
/* Examine file size */
fseek(fp, 0, SEEK_END);
fgetpos(fp, &fsize);
fclose(fp);
return fsize;
}
fpos_t is a variable meaning the size of the data, which is actually an unsigned integer; changing it to an int is not much of a problem.
Also, the above process changes the file pointer, i.e., the current read position, so the following is used to change it back.
sum.c
fpos_t fsize = 0;
fpos_t fsizeb = fseek(fp,0,SEEK_END);
fgetpos(fp,&fsize);
fseek(fp,fsizeb,SEEK_SET);
About this Site
The C language (bitter C), which is learned by suffering, is
This is the definitive C language introductory site.
It systematically explains the basic functions of the C language and
It is as complete as or more complete than any book on the market.