第一种方法:
int file_size(char *file_name)
{
FILE *fp;
long int file_size;
if((fp = fopen( file_name, "rb" )) != NULL)
{
if(( fseek(fp, 0, SEEK_END) ) < 0)
{
fclose(fp);
return -1;
}
file_size = ftell(fp);
fclose(fp);
}
prinft("The file_size = %ld", file_size);
return 0;
}
第二种方法:
int file_size(char *file_name)
{
long int file_size;
struct stat f_stat;
if( stat( file_name, &f_stat ) == -1 ){
return -1;
}
file_size = f_stat.st_size;
prinft("The file_size = %ld", file_size);
return 0;
}
阅读(1730) | 评论(0) | 转发(0) |