So the do/while loop is infinite, as I have been told before. Is there a better way to implement this loop?
typedef uint8_t BYTE;
int main(void) {
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;
}
}