如何在Linux上获取C中的文件长度? [英] How to get the file length in C on Linux?
本文介绍了如何在Linux上获取C中的文件长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找相当于微软的 _filelength Linux操作系统。我试过了,但这是不正确的。
I'm looking for the equivalent of Microsoft's _filelength in Linux. I tried this, but it's incorrect.
long _filelength(char *f)
{
struct stat st;
stat(f, &st);
return st.st_size;
}
if((hfile = fopen("data.arp","rb"))!=NULL)
fsize = _filelength(fileno(hfile));
如何在Linux上获取C中的文件长度?
How do I get the file length in C on Linux?
推荐答案
FILE *fp = fopen("filename", "rb");
fseek(fp, 0, SEEK_END);
int lengthOfFile = ftell(fp);
fclose(fp);
这篇关于如何在Linux上获取C中的文件长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文