C Programming Tips & Tricks





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Code Snippets
 List All
 Arrays
 Calculators
 Datatypes
 Date & Time
 File Manipulation
 Math Functions
 Multimedia
 Others
 




Display size of the file - C

Snippets  C  Display size of the file
Snippet On
Display file size




Code
  
Rate this page :
  [ 0 votes]


#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
int main()
{
int fp;
long file_size;
if ((fp = open(<q>f:abc.txt</q>, O_RDONLY)) == -1)
printf(<q>Error opening the file \n</q>);
else
{
file_size = filelength(file_handle);
printf(<q>The file size in bytes is %ld\n</q>, file_size);
close(fp);
}
return 0;
}

Output:
======
The file size in bytes is: 2048




Other Links

web hosting