Having problems with recover (pset5) now. This is what I'm doing:

Opening File
Until the end of file
   Reading 512 bytes to buffer
   Checking first 4 bytes of buffer to see if a jpg has just started
       A jpg has started. Check if there was one open
            Close the jpg that was opened
       Create new file
       Open new file
   If there is an open jpg write info from buffer to it

The manipulation of the images is perfect, but checkcs50 says the following:




check50 is extremely literal in the way it checks your results. The results need to match it's expected answers exactly, any small difference will result in a fail.

Fortunately the error report is often just as specific about the error. For example, the error report displays:

Checking for file  000.jpg. ... but received no such file!

Looking at the screenshot, your code is outputting an image named 0.jpg. This needs to be exactly 000.jpg.

This can be generated by using a special modifier syntax in the sprintf or snprintf statement which generates the file name, e.g.

snprintf(&filename, 8, "%03d.jpg", counter);
  • Once again you helped me a lot. Thank you !
    – FranGoitia
    Aug 10 '14 at 23:36
  • You said sprintf, but then used snprintf. Intentional?
    – ChiCubed
    Dec 31 '14 at 5:05
  • @TheBrainyOne Clarified. Thanks for the tip. Jan 5 '15 at 15:58
  • Is snprintf a function? Should not it be sprintf? Sep 11 '17 at 12:53

You must log in to answer this question.

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