GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


read-in file by DELTRON
// global scope
unsigned char * infilememstart = 0;
// --


FILE *fh = fopen("filename", "rb");
if ( !fh ) { MessageBox(NULL,"Error opening file.","ERROR",MB_OK | MB_ICONERROR); exit(1); }

fseek(fh, 0, SEEK_END);
int fsize = ftell(fh);
fseek(fh, 0, SEEK_SET);

// ** ALLOCATE MEMORY FOR IN-FILE
infilememstart = new unsigned char[fsize]; // will fail if not enough mem

if (!infilememstart) {// did not allocate memory!}

// ** READ IN IN-FILE
size_t bytesread = fread(infilememstart, fsize, 1, fh);    
fclose(fh);

if (bytesread!=fsize) {//didn't read everything we expected to read!}



----clean up-------
if (infilememstart)  {delete [] infilememstart;}