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


1 Answer 1


I saw that no one has answered your question so I decided to help you :) No problem, if your problem has been solved, just couple of things to be get noticed.

Just saw your while function using fgetc to loop till end of the file.Actually, fgetc reads a character at a time so,


How can you read a single character at a time inside a 512 block of memory and continue till end of the file...?

Doesn't make any sense..huh?

So, Actually you should have to use fread function inside your while condition because if EOF not reached so fread returns a value which is not less than 1 and if this condition is false, than actually you have reached EOF (end of the file)

Here is a executable demo link: https://cee.studio/?bucket=200712-UC2&name=Oodep.RUvg

If I helped you than please sure to tick the answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .