Thread: can someone please check this for logical errors?

  1. #1
    Shadow12345
    Guest

    can someone please check this for logical errors?

    I'm not sure what I'm doing wrong in this project, but the values I'm getting don't ring true to what they should be (the value printed to the window should be 4, but instead i get like 22586 or something)

    Code:
    	ifstream fin(fileName, ios::in | ios::binary | ios::nocreate);
    
    if(fin.fail()){
    MessageBox(NULL, "UNABLE TO OPEN MODEL FILE", "ERROR", MB_OK);
    return;
    }
    char x[50];
    
    fin.seekg(0, ios::end);			//SEEK TO END OF FILE, STREAM OFF
    long filesize = fin.tellg();	//GET SIZE IN BYTES OF FILE
    fin.seekg(0, ios::beg);			//SEEK BACK TO BEGINNING
    byte*buffer = new byte[filesize];
    fin.read(buffer, filesize);			//READ STUFF FROM FILE INTO A BUFFER
    fin.close();	
    const byte * ptr = buffer;	
    MS3DHeader *pHeader = (MS3DHeader*) ptr;
    ptr += sizeof(MS3DHeader);
    
    sprintf(x, "version: %d", (int)pHeader->m_version);
    SetWindowText(hWnd, x);
    Sleep(tts);

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Do you want to traverse pHeader or ptr?

    pHeader += sizeof(MS3DHeader);

    Kuphryn

  3. #3
    Shadow12345
    Guest
    I meant to traverse ptr, the idea of this setup is to read everything into a buffer, then set up a pointer to that buffer so you can extract necessary data and increase the pointer to the next portion of the buffer. MS3DHeader is just the first thing in a list of data items that are in the file, but for reason it's not getting read correctly and it's ........ing me off

    EDIT:
    Do you know what the ios::nocreate bit does?

    Originally posted by MSDN
    Opens a disk file and attaches it to the stream’s filebuf object. If the filebuf object is already attached to an open file, or if a filebuf call fails, the ios::failbit is set. If the file is not found, then the ios::failbit is set only if the ios::nocreate mode was used.
    I don't friggin get it
    Last edited by Shadow12345; 12-27-2002 at 12:40 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM