All of my program seems to be functioning but my JPEG images are completely blank. I'm not sure, but I think the error is somewhere in this code:

if ((buffer[0] == 0xFF) && (buffer[1] == 0xD8) && (buffer[2] == 0xFF) && (buffer[3] == 0xE0))

    sprintf(fn, "%03d.jpg", f);
    filer = fopen(fn, "a");

    f++, x++;

    printf("image %s\n", fn);
    printf("iteration %i\n", f + 1);

The files that were created are each 0 bytes in size.

  • 1
    Remember that the last byte in the 4 byte sequence that identifies a jpg can not only be 0xe0 but also 0xe1.
    – user103853
    Aug 18, 2014 at 23:29
  • Firstly, pseudocode is preferred as per the academic honesty rules; please replace it accordingly. Secondly, without more information about what you've tried, and what other functions do its hard to help you. I would suggest though that you set up just one jpg in your program, then write a little loop that gathers in data and writes it into that one jpg file once it finds a jpg in raw and stops when it finds another. Then check the output and this will give you a better idea if the problem is with creating jpg files, or collecting the data.
    – user103853
    Aug 18, 2014 at 23:35
  • @chris the reason I did not use pseudocode was becuase I was pretty sure that the error was in the syntax and not in the idea.
    – user1475
    Aug 18, 2014 at 23:41

1 Answer 1


Turns out that I just was fwriting to the input file! Thanks everyone for all your help!

You must log in to answer this question.

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