My code compiles and actually recovers 1 single image, an empty one, then it quits. I suspect the issue is related to the amount of bytes I'm reading from card.raw, but I can't be sure. I tried moving things around a lot, always get the Seg Fault. This is the only configuration that I was able to compile and run without errors, but I only get the lonely 000.jpg in the directory. Anyone can tell me what I am doing wrong? I used copy.c as a base for my code. And I left the "sanity checks" for the opening / closing of files out, here, to save space.
// remember filenames
char* infile = "card.raw";
char title[8]; //leave room for \0
uint8_t buffer[512];
// open input file
FILE* inptr = fopen(infile, "r");
// create output file for new JPG file
FILE* outptr = 0;
// loop through card.raw
for (int i = 0; i < *infile; i++)
{
// number of recorded files tracker
int counter = 0;
if (fread(&buffer, 512, 1, inptr) == 1)
{
if ((buffer[0] == 0xff) && (buffer[1] == 0xd8) && (buffer[2] == 0xff) && ((buffer[3] == 0xe0) || (buffer[3] == 0xe1)))
{
// create new title for new JPG file
sprintf(title, "%.3d.jpg", counter);
// make new JPG file
outptr = fopen(title, "a");
// write 512 bytes 1 by 1 to new JPG file
fwrite(&buffer, 512, 1, outptr);
// close new JPG file
fclose(outptr);
}
counter++;
}
}
// close card.raw
fclose(inptr);
// that's all folks
return 0;
for (int i = 0; i < *infile; i++)