将文件转换为数组保存在内存中
Posted cristiano-duan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将文件转换为数组保存在内存中相关的知识,希望对你有一定的参考价值。
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *image = fopen("big_face.yuv", "r");
if(NULL == image)
{
printf("open file failed!");
return 0;
}
fseek(image, 0, SEEK_END);
int nFileLen = ftell(image);
rewind(image);
unsigned char* image_dat = (unsigned char*)malloc(nFileLen+1);
if(NULL == image_dat)
{
printf("malloc failed!");
fclose(image);
return 0;
}
fread(image_dat, sizeof(unsigned char), nFileLen, image);
image_dat[nFileLen] = '