Dotcpp  >  编程教程  >  stdio.h头文件  >  C语言ftell()函数:偏移量是从文件开始算起的字节数

C语言ftell()函数:偏移量是从文件开始算起的字节数

点击打开在线编译器,边学边练

函数名: ftell

头文件:<stdio.h>

函数原型: long ftell(FILE *stream);

功 能:  偏移量是从文件开始算起的字节数。

参 数: FILE *stream   需要返回指针的文件流

返回值:成功   返回当前文件指针的位置  ,出错   返回-1L,是长整数的-1值。


程序例:  打开文件,在讲字符串输入文件流中,并输出文件的长度

#include<stdio.h>

int main(void){

   FILE *stream = fopen("test.txt", "w+");

   if(!stream){

      printf("can not open the file\n");

      return 0;

   }

   fprintf(stream, "www.dotcpp.com");

  printf("The file pointer is at byte %ld\n", ftell(stream));

   fclose(stream);

   return 0;

}


运行结果

The file pointer is at byte 14



本文固定URL:https://www.dotcpp.com/course/516

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)