If anyone cound take a look at my code. My recover gets all 50 images and they look good, but my Check50 fails for 'expected an exit code of 0, not output of "file opened\nfile named\n"'
//2. REPEAT UNTIL EOF / 3. READ 512 BYTES TO BUFFER
while (fread(&buffer, 1, 512, inptr) > 0)
{
//4. START A NEW JPEG?
// does the first 4 bytes resemble a jpeg struct
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
{
printf("found a header\n");
//we have found a jpeg set ready to true to start writing to file
ready = true;
//if we are already working on a JPEG close it
if(count > 0)
{
printf("found new file\n");
//close any open files
fclose(outptr);
}
// Start a new JPEG
// print new filname
sprintf(filename, "%03d.jpg", count);
printf("%s\n", filename);
//open new file
outptr = fopen(filename, "w");
if (outptr == NULL)
{
fprintf(stderr, "Could not open %s.\n", filename);
return 5;
}
// increase count to track filenames
printf("count: %i\n", count);
count++;
}
if(ready == true)
{
printf("writing\n");
//7. WRITE 512 BYTES UNTIL COMPLETE OR NEW JPEG
fwrite(buffer, 1, 512, outptr);
}
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
//release mallocs
free(filename);
return 0;
}