C 語言中的 ftell() 函式
在 C 語言中,ftell() 會返回相對於檔案起始位置的指定流的當前檔案位置。此函式用於在將檔案指標移動到檔案末尾後獲取檔案的總大小。它以 long 型別返回當前位置,而檔案可以包含超過 32767 個位元組的資料。
以下是 C 語言中 ftell() 的語法:
long int ftell(FILE *stream)
以下是 ftell() 中使用的引數:
stream − 指向標識流的 FILE 物件的指標。
以下是 C 語言中 ftell() 的一個示例。
假設我們有一個名為“one.txt”的檔案,其內容如下。
This is demo text! This is demo text! This is demo text!
現在,我們來看看該示例。
示例
#include <stdio.h>
#include<conio.h>
void main () {
FILE *f;
int len;
f = fopen("one.txt", "r");
if(f == NULL) {
perror(“Error opening file”);
return(-1);
}
fseek(f, 0, SEEK_END);
len = ftell(f);
fclose(f);
printf("Size of file: %d bytes", len);
getch();
}輸出
Size of file: 78 bytes
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP