Function name : filelength
Header file : <io.h>
Function prototype : int filelength(int handle);
Function : Count the number of bytes of the file opened by the open() function
Parameters : int handle is the file handle to be counted
Return value : Returns the length of the open file
Program example : Use the open function to open a file and count the number of bytes in the file
#include<stdio.h>#include<io.h>#include<fcntl.h>intmain(void){intfd=open(D:\a.txt,_O_RDWR+O_CREAT);if(fd==-1 ){print f(cannotreatethefilen);return1;}intlen=filelength(fd);printf(thefilelengthis%dn,len);close(fd);printf(OK);return0;}
Running results
thefilelengthis46