问:如何获取一个文件的大小?
答:可以使用两个函数:fseek()和ftell()。实例如下:
long getFileSize(FILE *pFile)
{
long size = 0;
if (pFile == NULL)
{
return -1;
}
fseek(pFile, 0L, SEEK_END); // Moves the file pointer to end of file.
size = ftell(pFile); // Gets the current position of a file pointer.
fseek(pFile, 0L, SEEK_SET); // Moves the file pointer to beginning of file.
return size;
}