0

What can possibly make the following errors?

:) recover.c exists
:) recover.c compiles
:( recovers 000.jpg correctly
 \ expected an exit code of 0, not output of "ÿØÿà\u0000\u0010JFIF\u0000\u0001\u0002\..."
:( recovers middle files correctly
 \ expected an exit code of 0, not output of "ÿØÿà\u0000\u0010JFIF\u0000\u0001\u0002\..."
:( recovers last file correctly
 \ expected an exit code of 0, not output of "ÿØÿà \u0000\u0010JFIF\u0000\u0001\u0002\..."

Below is inside a while loop that reads card.raw:

// define block size
#define BLOCK 512

 int main(void)
{
    // char array to store the resultant string
    char storage[4];

   // open input file
    FILE* cardptr = fopen("card.raw", "r");

    if (cardptr == NULL)
    {
        printf("File couldn't open\n");
        return 1;
    }

    // open recovering JPEGs file
    FILE* recptr = NULL;

    // Define unassigned integer block size of 512 Bytes 
    uint8_t buffer[BLOCK] = {};

   // create counter for new JPEGs
    int counter = 0;

  //read card
    while (fread(buffer, sizeof(buffer), 1, cardptr) == 1)
    {

Thanks for helping

  • There's no way to tell from what little code is posted. It could be a stray printf statement that you left in the code, or any number of other issues. – Cliff B Mar 10 '16 at 19:57
  • It looks like an exit code of 0 is expected, but you're writing to the screen. What happens if you comment out your sprintf on the 4th line? – Sean DiSanti Mar 10 '16 at 21:57
  • Following your comments, I've updated the code above by presenting what is before processing the image. – cocobongo Mar 14 '16 at 18:38
0

The problem lies in these two lines of code:

// char array to store the resultant string
char storage[4];
....
sprintf(storage, "%03d.jpg", counter);

I had to dig through the edits to find it, but this is almost certainly causing your problem. The sprintf() call creates a string of 8 characters, including the \0, but then tries to stuff that into a character array of only 4 bytes. It simply isn't large enough. Unfortunately, this won't trigger a runtime error, but it will cause all kinds of downstream problems, like corrupt data, bad file names, etc.

There may be other problems, but this is certainly causing it's share of trouble.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • With your tips, I made few adjustments in my Recover. Including the size of the string, I changed, inside while loop, the IF condition to close any existent file. Thanks Cliff – cocobongo Mar 22 '16 at 18:35

You must log in to answer this question.

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