   Help with reading a .MD2 file.
  Hello, I'm trying to load a .MD2 file for a program I'm making using OpenGl in c++. Pretty much I'm just having general programing trouble.Now, all .MD2 files start out with IDP2, I've opened one in notepad to verify this. Here is my code.ifstream input;input.open("Model.md2", istream::binary);char buffer[64];input.read(buffer, 4); //Should be "IPD2", if this is an MD2 fileif (buffer[0] != 'I' || buffer[1] != 'D' ||buffer[2] != 'P' || buffer[3] != '2') {return NULL;}For some reason I get NULL.buffer = 0x0026f5c4 "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ,2Fj"I'm not too sure why its giving me this, so I'd thought I'd post for a little help.   
  first off,  just to point out, it's best to read the whole file in one shot,  header and all, just becasue memory access is faster than Hard disk access.that being said, try clearing the memory out first, it's good to clear memory first so you can see what the read is doing to the data.  and then, try reading the first 4 bytes into a single int,  and comparing it to 844121161so just try thisint MagNum = 0;input.read((char*)&MagNum,4);if(844121161 == MagNum)return true;return false;EDIT*  also,  when reading files like this,  it's best to use unsigned char's   ;Quote:Original post by Argo15For some reason I get NULL.buffer = 0x0026f5c4 "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ,2Fj"I'm not too sure why its giving me this, so I'd thought I'd post for a little help.Consider the two additions to track down the problem. I'm guessing the file is not even being opened to begin with, and since buffer is not initialized, the memory is the uninitialized VS debug buffer, Ì.ifstream input;input.open("Model.md2", istream::binary);if(!input.is_open()){  MessageBox(0, "Could not open the file", "Error", MB_ICONERROR);}char buffer[64] = {0}; // Always clear your memory or you will run into horrible bugs!input.read(buffer, 4); //Should be "IPD2", if this is an MD2 fileMy best guess atm, good luck!   ;  It's really the oddest thing, when I debug it gives me an error, but when i run the .exe I was able to load a .MD2 just fine. The problem with debugging is that it couldn't read the file.   ;  When you "debug" from Visual Studio, the current directory changes, so my guess would be that the current directory where the application was being debugged from did not contain the file. A simple way to get this done for the sake of debugging is hard coding the file name, otherwise you can change the Working Directory in the project Debugging options.   