0

I'm not sure what I'm doing wrong here. I wait until the first jpg is reached, then I make new files until the end of the file. This is btw a very difficult assignment!!! check50 says it complies but was killed by the server.

typedef uint8_t BYTE;

int main(void)
{

    FILE* file = fopen("card.raw", "r");
    if (file == NULL)
    {
        printf("Doesnt work dog\n");
        return 1;
    }

    FILE* img = NULL;
    int jpgnum = 1;
    BYTE buffer[512];
    //read until first jpg
    do
    {
        BYTE buffer[512];
        fread(buffer, sizeof(buffer) , 1, file);
    }
    while (buffer[0] != 0xff && buffer[1] != 0xd8 && buffer[2] != 0xff && (buffer[3] != 0xe0 || buffer[3] != 0xe1));

    while (!feof(file))
    {
       BYTE buffer[512];
       char jpgname[8];

       // finding a new jpg
       if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] == 0xe0 || buffer[3] == 0xe1))
       {
            if (img != NULL)
            {
                fclose(img);
            }
            sprintf(jpgname, "%03d.jpg", jpgnum);
            img = fopen(jpgname, "w");
            jpgnum++;
            fwrite(buffer, sizeof(buffer), 1, img);
       }
    fwrite(buffer, sizeof(buffer), 1, img);    
    }
    fclose(img);
    fclose(file);
    return 0;
}
0
2

Did you try to run it on the appliance before checking with check50? I did and it goes in an infinite loop. That's why the server killed it. More precisely the infinite loop is because of your first do-while loop. If you want more help please edit your question or ask a new one, but if the question is

Why was recover.c killed by server

I think I answered your question

1
  • True, well at least I know what is incorrect now :p I asked the question in a different forum – Fijj Sep 8 '15 at 21:33

You must log in to answer this question.

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