Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help in c++, going backwards through binary files

Options
  • 29-03-2005 4:34pm
    #1
    Registered Users Posts: 221 ✭✭


    I hope someone can help me
    i'm wondering how to search backwards through a binary file i havent
    done it in ages and can't remeber the notation

    if anyone can help that would be great thanks

    -Sean


Comments

  • Registered Users Posts: 2,082 ✭✭✭Tobias Greeshman


    int start_pos = fgetpos(fp, &start_pos);

    Use the seek function to move to the end of the file
    fseek(fp, SEEK_END, 0L);

    Then use the above function
    do {
    int i = fseek(fp, SEEK_END, -chunk);
    } while(i != start_pos);

    You get the idea, get start position, move to end of file, read data there move back x bytes read that data, continue until you reach the start of the file.

    My code is probably a bit off, but ya get the idea (i've written it in C, but C++ standard library has similar functions to do the same thing).


Advertisement