Dotcpp  >  编程教程  >  io.h头文件  >  C语言filelength()函数:统计由open()函数所打开的文件的字节数

C语言filelength()函数:统计由open()函数所打开的文件的字节数

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

函数名:filelength

头文件:<io.h>

函数原型: int filelength(int handle);

功能:统计由open()函数所打开的文件的字节数

参数: int handle  为要统计的文件句柄

返回值: 返回打开文件的长度


程序例:使用open函数打开文件,并且统计文件的字节数

#include<stdio.h>

#include<io.h>

#include<fcntl.h>

int main(void){

   int fd=open("D:\\a.txt",_O_RDWR+O_CREAT);

   if(fd==-1){

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

      return 1;

   }

   int len=filelength(fd);

   printf("the file length is %d\n",len);

   close(fd);

   printf("OK");

   return 0;

}

 

运行结果

the file length is 46



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

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在线编译      (登录可减少运行等待时间)