typedef uint8_t BYTE; int main(int argc, char* argv[])
{ // TODO // open input file FILE* inptr = fopen("card.raw", "r"); if (inptr == NULL) {
printf("Could not open.\n");
return 1;
}
// temporary block reading
BYTE buffer[512];
// found jpgs name and number
int file_num = 0;
char file_name[8];
// open first out file
char* outfile = NULL;
FILE* outptr = fopen(outfile, "w");
if (outptr == NULL)
{
fclose(inptr);
fprintf(stderr, "Could not create %s.\n", outfile);
return 2;
}
// reading to the file end
while (!feof(inptr))
{
// read first block
fread(&buffer, sizeof(BYTE), 512, inptr);
// check jpg sequences
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] == 0xe0 || buffer[3] == 0xe1))
{
while (!feof(inptr)) // after getting the first jpg read to the end
{
fwrite(&buffer, sizeof(BYTE), 512, outptr);
fread(&buffer, sizeof(BYTE), 512, inptr);
// ckeck
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] == 0xe0 || buffer[3] == 0xe1))
{
// close and name the file
fclose(outptr);
sprintf(file_name, "%03d.jpg", file_num);
file_num++;
// open new out file
char* outfile = NULL;
FILE* outptr = fopen(outfile, "w");
if (outptr == NULL)
{
fclose(inptr);
fprintf(stderr, "Could not create %s.\n", outfile);
return 2;
}
}
}
}
}
return 0;
}