fopen获取图像文件数据和大小
参考 fopen , fread fwrite 函数读写二进制文件 问题总结
C得到文件的大小
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
FILE* fp = NULL;
int nFileLen = 0;
fp = fopen("Test.jpg", "rb");
if (fp == NULL)
{
cout << "can"t open file" << endl;
return 0;
}
fseek(fp,0,SEEK_END); //定位到文件末
if ((nFileLen = ftell(fp))<1)//文件长度
{
fclose(fp);
return 0;
}
char* data = (char *)malloc(sizeof(char)*(nFileLen+1));
if (NULL == data)
{
fclose(fp);
return 0;
}
fread(data, nFileLen, 1, fp);
free(data);
fclose(fp);
return 0;
})
return 0;
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: PHP之找任意两个字符串的最大相同部分
- 下一篇: PHP浮点数比较大小
