如何用C语言获取文件的大小
1个回答
展开全部
两种方法:
1、用stat()函数来获取
1
2
3
4
5
6
7
int main()
{
struct stat st ;
stat( "file.txt", &st );
printf(" file size = %d\n", st.st_size);
return 0;
}
2、用ftell()函数来获取
1
2
3
4
5
6
7
8
int main()
{
FILE *fp;
fp=fopen( "file.txt", "r");
fseek(fp, 0L, SEEK_END );
printf(" file size = %d\n", ftell(fp) );
return 0;
1、用stat()函数来获取
1
2
3
4
5
6
7
int main()
{
struct stat st ;
stat( "file.txt", &st );
printf(" file size = %d\n", st.st_size);
return 0;
}
2、用ftell()函数来获取
1
2
3
4
5
6
7
8
int main()
{
FILE *fp;
fp=fopen( "file.txt", "r");
fseek(fp, 0L, SEEK_END );
printf(" file size = %d\n", ftell(fp) );
return 0;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询