動的にメモリを確保してファイルを開く
#include <stdio.h> #include <stdlib.h> void main() { // ファイルオープン FILE* fp = fopen("hoge.bmp", "rb"); if (!fp) exit(1); // ファイルサイズ計算 fseek(fp, 0, SEEK_END); int size = ftell(fp); // 動的にメモリを確保 unsigned char* p = (unsigned char*)malloc(size); if(p == NULL) exit(1); // 画像データ読み込み fseek(fp, 0, SEEK_SET); fread(p, 1, size, fp); // メモリ解放 free(p); fclose(fp); }