As I'm sure you're aware, the goal of this assignment is to recover a number of deleted jpeg files from a provided memory card image. My code compiles and executes, but I'm receiving the error "Fatal error: glibc detected and invalid stdio handle". No images are recovered before the program aborts.
I tried running this through debug50, and the problem seems to happen during fwrite() on line 57, but I can't tell what's going wrong. I tried using printf() to return the positions, pointers, and values of each element in the buffer array. And it evidently goes through two cycles before it stops.
In the first cycle, only element number 11 has a value. In the second cycle, only elements 0-13 have values. And for some strange reason, it indents the printed line for element 512. I'm at a complete loss. I have no idea what's happening here. I've been stuck on this problem for months now, and I desperately need to move on. Please help. Thanks in advance.
Here is my code: https://pastebin.com/H3FqxLiU