1.fseek
函數原型:
參數說明:stream,文件流指針;offest,偏移量;orgin,原(始位置。其中orgin的可選值有SEEK_SET(文件開始)、SEEK_CUR(文件指針當前位置)、SEEK_END(文件結尾)。
函數說明:對于二進制模式打開的流,新的流位置是origin + offset。
2.ftell
函數原型:long int ftell ( FILE * stream );
函數說明:返回流的位置。對于二進制流返回值為距離文件開始位置的字節數。
獲取文件大小C程序(file.cpp):
int main ()
{
FILE * pFile;
long size;
pFile = fopen ("file.cpp","rb");
if (pFile==NULL)
perror ("Error opening file");
else
{
fseek (pFile, 0, SEEK_END); ///將文件指針移動文件結尾
size=ftell (pFile); ///求出當前文件指針距離文件開始的字節數
fclose (pFile);
printf ("Size of file.cpp: %ld bytes./n",size);
}
return 0;
}
新聞熱點
疑難解答
圖片精選