0

I have been working through this problem and cannot figure out why this while loop is producing an infinite loop and no image files, which is probably caused by a logic error on my part. As far as I understand from the manpages, fread should return 1 as long as it is a successful read of the given size parameter and the read quantity is 1. But, it should return zero as long it cannot read a full quantity of the given size.

So, my understanding is that this while loop will continue to have a true condition only until it fread can no longer read a full segment of 512 bytes into my buffer array. Clearly, though, there is some error that I cannot find because it does not break out of the loop nor produce any images.

I have gone through all of the relevant topics that I could find on here (and through a web search) regarding similar issues to mine with this problem. Most of these did not help, though, as they either did not have much/any code snippets to see to help understand the suggestion/answer or had other errors produce their problems (given that the solutions provided were already implemented in my code).

Hopefully this provides sufficient information for someone to help point me in the right direction. Thank you in advance.

1
  • Removed the code to avoid any issues regarding academic honesty. Jan 7, 2021 at 16:31

1 Answer 1

0

Didn't see an infinite loop, just no files being created.

First, no signatures are being found. There's an error in the signature check:

buffer[2] == 1

Next, after the first file, the remaining files are created with incorrect file names. Specifically, there is no file extension on the file names.

There may be other issues, but this should get you going.

1
  • When I added a printf statement to debug earlier, it appeared to be in a while loop and it got kicked out of check50 for timing out. But, that might not have been the case as this solved my issue. Thanks! Jan 6, 2021 at 21:17

You must log in to answer this question.

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