C庫函數long int ftell(FILE *stream) 返回給定流的當前檔位置。
聲明
以下是ftell()函數的聲明。
long int ftell(FILE *stream)
參數
-
stream -- 這是一個檔對象的標識流的指針。
返回值
此函數返回的位置指示器的當前值。如果發生錯誤,則返回-1L,全局變數errno設置為正值。
實例
下麵的例子演示了如何使用ftell()函數。
#include <stdio.h> int main () { FILE *fp; int len; fp = fopen("file.txt", "r"); if( fp == NULL ) { perror ("Error opening file"); return(-1); } fseek(fp, 0, SEEK_END); len = ftell(fp); fclose(fp); printf("Total size of file.txt = %d bytes ", len); return(0); }
假設我們有一個文本檔file.txt的,它具有以下內容:
This is xuhuhu.com
讓我們編譯和運行上面的程式,這將產生以下結果:
Total size of file.txt = 21 bytes
上一篇:
fsetpos() - C語言庫函數
下一篇:
fwrite() - C語言庫函數