0

check50 reverts with following results and don't quite understand what these referring to:

:) recover.c exists
:( recover.c compiles
   \ expected an exit code of 0, not standard error of "recover.c:4:10: fatal error: 'bmp.h' fi..."
:| recovers 000.jpg correctly
   \ can't check until a frown turns upside down
:| recovers 001.jpg through 014.jpg correctly
   \ can't check until a frown turns upside down
:| recovers 015.jpg correctly
   \ can't check until a frown turns upside down

My code is as follows:

#include <stdio.h>
#include <stdlib.h>

#include "bmp.h"

int main(void)
{
    BYTE buffer[512];

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

    if (file == NULL)
    {
        printf("Could not open 'card.raw'.\n" );
        return 1;
    }

    // open output file
    char* outfile = NULL;
    FILE* outptr = fopen(outfile, "w");

    if (outptr == NULL)
    {
        fclose(file);
        fprintf(stderr, "Could not create %s.\n", outfile);
        return 1;
    }

    int counter = 0;

    while (!feof(file))
    {
        if (buffer[0]==0xff && buffer[1]==0xd8 && buffer[2]==0xff && (buffer[3]==0xe0 || buffer[3]==0xe1))
        { 
            sprintf (outfile, "%03d.jpg", counter);

            if (outptr != NULL)
            {
                fclose(outptr);                
            }    

            fread (buffer, sizeof(buffer), 1, file);

            fwrite (buffer, sizeof(buffer), 1, outptr);

            counter++;
        }   
        else
        {
        fread (buffer, sizeof(buffer), 1, file);

        fwrite (buffer, sizeof(buffer), 1, outptr);

        }
    }


    // close infile
    fclose(file);

   // close outfile
    fclose(outptr);

    // that's all folks
    return 0;
}

Grateful if anyone of you can give some guidance. Many thanks.

5

Just like the error message says, your code doesn't compile, and that because you have included the bmp.h header file on top, which was used in resize and copy, but was included in the bmp directory, not in the jpg directory where this code lies. Simply remove the

#include "bmp.h"

Edit

You should also redefine BYTE as it was included in bmp.h but now it's not included in this directory. Use

#include <stdint.h>

on top and then

typedef uint8_t  BYTE;

This will allow your code to compile, but you still have a long way before your code actually works.


If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark. And don't forget to keep coding!

| improve this answer | |
  • Chris - Thanks so much! Will keep working on that. – Taz Sep 10 '15 at 23:33
  • If this answered your question, please mark it as accepted. :) – ChrisG Sep 11 '15 at 16:50

You must log in to answer this question.

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