How to get the file length in C on Linux

How to get the file length in C on Linux given the address of the file (e.g. "/tmp/a.txt")?

asked May 27, 2014 by Eric Z Ma (44,280 points)

1 Answer

 
Best answer

This function returns the length of the file:

#include <sys/stat.h>

long file_length(char *f)
{
    struct stat st;
    stat(f, &st);
    return st.st_size;
}
answered May 28, 2014 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...