ftell() – C语言库函数

C库函数long int ftell(FILE *stream)  返回给定流的当前文件位置。

声明

以下是ftell()函数的声明。

longint 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 xyhtml5.com

让我们编译和运行上面的程序,这将产生以下结果:

Total size of file.txt = 21 bytes

以上是ftell() – C语言库函数的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>