Download Horizon :: Staff Members :: Save Vault :: XboxMB YouTube


Old 02-18-2012   #1 (permalink)

Hetelek's Avatar
sh042067
Join Date: Sep 2010
Location: NY
Posts: 1,675
Thanks: 1,004
Default Reading File Help

Hey, I am trying to make a XDBF class, and I am reading a file and this is getting ridiculously annoying.

First: I open my file...
Code:
openedFile = fopen(path, "r+");
It works, and my whole constructor works correctly:

I know it works correctly, because I looked at all of the entries that it loaded and stuff.

Now, the constructor ends, and I do this to extract an entry:
Code:
    XDBF a("C:\\Users\\Stevie\\Desktop\\file.gpd");
    FILE *f;
    f = fopen("C:\\Users\\Stevie\\Desktop\\a.png", "wb");
    fseek(f, 0, SEEK_SET);

    XDBF::Entry *entry = a.get_entry_by_id(0x1C);
    char *buff = a.extract_entry(entry);
    a.close();

    int size = entry->length;
    QMessageBox::information(this, "", QString::number(size), QMessageBox::Ok);
    fwrite(buff, sizeof(char), size, f);

    fclose(f);
Now, here are the 2 functions I call(get_entry_by_id, and extract_entry):
Code:
XDBF::Entry* XDBF::get_entry_by_id(long long identifier)
{
    Entry* entries = get_entries();
    for(unsigned int i = 0; i < get_header()->entry_count; i++)
        if(entries[i].identifier == identifier)
            return &entries[i];

    return NULL;
}

char *XDBF::extract_entry(Entry *entry)
{
    if(openedFile == NULL)
        return NULL;

    unsigned int offset = get_offset(entry->offset_specifier, h);
    fseek(openedFile, offset, SEEK_SET);
    char *data = new char[entry->length];
    unsigned int poophead = (unsigned int)data;

    fread(data, entry->length, sizeof(char), openedFile);

    return data;
}
Now once I get the char* from 'extract_entry', I write it to a file... It's really dumb because it reads the data incorrectly... I don't know how it's possible, but it gets the bytes:

Code:
89 50 4E 47 0A...
out of the file, while the real bytes are:

Code:
89 50 4E 47 0D...
The bytes that I posted first don't even exist in the GPD... I also look at the location that it seeks to before reading the entry in the 'extract_entry' function, and it's correct...

I am new the C++, so there is probably some stupid stuff I did in the code posted. Thanks for any help.
__________________





Hetelek is offline Send a message via AIM to Hetelek


Old 02-18-2012   #2 (permalink)
Regular Member
austin12456's Avatar
Join Date: Jul 2010
Posts: 1,265
Thanks: 1,172
Default Re: Reading File Help

"rb+" instead of "r+"

r is for text files, and rb is read binary
__________________
austin12456 is offline
The following users thanked this post: Austin, Dwack, Hetelek, RZRClanLeader


Old 02-18-2012   #3 (permalink)

Hetelek's Avatar
sh042067
Join Date: Sep 2010
Location: NY
Posts: 1,675
Thanks: 1,004
Default Re: Reading File Help

Quote:
Originally Posted by austin12456 View Post
"rb+" instead of "r+"

r is for text files, and rb is read binary
-___________________________________-

That worked. Please close.
__________________





Hetelek is offline Send a message via AIM to Hetelek




Old 02-19-2012   #4 (permalink)
Chris's Avatar
Join Date: Sep 2010
Location: California
Posts: 12,085
Thanks: 11,668
Default Re: Reading File Help

Closed.
Chris is offline
The following user thanked this post: Hetelek

Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:29 AM.


 

Powered by vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
COPYRIGHT (c) 2010 - 2013 - XboxMB - DESIGN BY:
EDENWEBS.COM