0

I am receiving a segmentation fault stemming from line 95. This is where I am attempting to continue to write the remainder of a JPG file after finding it.

  [code hidden]
0

Not sure if this is what finally got it for me, but I ended up using unsigned char for my buffer type. I tried to use BYTE, but it was giving me problems.

Another thing that may be an issue for you is that it appears you're writing every byte to a file. We don't want to start writing until we've received the first JPEG header. I believe it needs to be checked outside of the "found JPG header" loop as well.

Some other thoughts:

The only thing that you want to do differently inside of your JPEG header loop dependent on first_jpg_found is either close the previous file or set first_jpg_found to 1. Other than that, you're doing the same filename/opening/checking regardless of that condition, so you can refactor that code by pulling it out of the if/else blocks.

You can also write just one time instead of 3.

0

As it turns out... after spending time searching for the definition of a segmentation fault... I realized when I initialized the FILE *img I should have set it to NULL (as in FILE *img = NULL). That was the problem, everything worked fine after that!

1

You must log in to answer this question.

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