Check50check50
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
:) 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;
}
#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;
}