memmove problem

This is a discussion on memmove problem within the C++ Programming forums, part of the General Programming Boards category; I'm redoing bible a program I wrote which parses a raw text file and produces a file of my own ...

  1. #1
    Chad Johnson
    Join Date
    May 2004
    Posts
    154

    memmove problem

    I'm redoing bible a program I wrote which parses a raw text file and produces a file of my own format.

    I use some C++, but my question concerns memmove (I think at least), so I'm posting in the C section.

    Here's the format of my file:

    (2 byte) length of title in bytes
    <title>
    (1 byte) length of copyright in bytes
    <copyright text>
    (2 bytes) number of books
    (4 bytes) byte locations of each book
    (2 bytes) length of book name in bytes
    <book name>
    (2 bytes) number of chapters in book
    (4 bytes) byte locations of each chapter
    (2 bytes) number of verses in chapter
    (4 bytes) byte locations of each verse
    (2 bytes) length of each verse in bytes
    <verse text>

    Obviously, the book and chapter information repeats for every book and chapter, respectively.

    What's happening, as you can see from this picture, is the locations of the chapters are not writing correctly after it reaches a certain point (I commented out writing the verse locations and book locations). In the text highlighted in black, the value is being written as B4 98 0D 0A, when it SHOULD be written as B4 98 0A. I'll attach the source too.

    The four-byte groups are actual (correct) chapter locations for the book of Genesis.

    I'm almost 100% sure the bug is in the function ParseToBuffer

    EDIT: actually, I commented it's the book locations I didn't comment out. The verse location and chapter writing is what is commented out.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by ChadJohnson; 03-12-2005 at 01:30 PM.

  2. #2
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    Now that I look at it, the stupid program is not writing any of the locations correctly. They're point *almost* to the right locations, but they're a little off.

    Does anyone have any idea why???

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    You need to open your file streams in binary mode or "translations" will occur when you read and write on Windows based machines.

    Have a look-see at "test.bin" after running this:
    Code:
    #include <fstream>
    #include <iostream>
    using namespace std;
    
    int main()
    {
        ofstream f("test.bin"); // use f("test.bin", ios::out | ios::binary);
    
        if (!f)
        {
            cout << "Failed" << endl;
            return 1;
        }//if
    
        f.put(0x0a);
        f.close();
    
        return 0;
    }//main
    gg
    Last edited by Codeplug; 03-12-2005 at 02:45 PM.

  4. #4
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    Ah man! Thank you so much! I've been trying to figure this out for days. I'll definitely remember that from now on.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    C++ on the C++ forum please....
    [edit]
    Oh I see your opening comment now... whatever... try not to post C++ on the C forum as it confuses poor people like me!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21