方法1:
#include <stdio.h>
int main()
{
int len = 0;
char *filename = "f:/untitled.bmp";
FILE *fp = fopen(filename, "r");
if(fp != NULL)//fp==NULL时返回该文件不能打开
{
fseek(fp, 0, SEEK_END);
len = ftell(fp);
printf("len=%d bytes/n", len);
fclose(fp);
}
return 0;
}
方法2:
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int main()
{
int len;
char *filename = "f:/untitled.bmp";
int handle = open(filename, O_RDONLY);
if(handle >= 0)
len = filelength(handle);
else
len = -1;
close(handle);
printf("len=%d bytes/n", len);
return 0;
}