i am getting a timed out error but don t understand why...? also i can see all the pictures except the last one (049.jpg) ...
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("missing command line argument\n");
return 1;
}
FILE *card = fopen(argv[1], "r");
if (card == NULL)
{
return 1;
}
int count = 0;
int card_size = sizeof(card);
FILE *img = NULL;
while (card_size <= 512)
{
//read 512 bytes from the file (card)
unsigned char photos[512];
fread(photos, 512, 1, card);
//check if JPEG
if (photos[0] == 0xff && photos[1] == 0xd8 && photos[2] == 0xff)
{
if ((photos[3] & 0xf0) == 0xe0)
{
//close previous file
if (count > 0)
{
fclose(img);
}
//create a new file 00count.jpeg
char pic[8];
sprintf(pic, "%03i.jpg", count);
img = fopen(pic, "w");
//check that the file was created successfully
if (img == NULL)
{
printf("file not created\n");
return 1;
}
//start writting in the file
fwrite(photos, 512, 1, img);
count++;
}
else
{
//keep writting in the current file
fwrite(photos, 512, 1, img);
}
}
else if (img != NULL)
{
//keep writting in the current file
fwrite(photos, 512, 1, img);
}
card_size = card_size - 511;
}
//close all files
fclose(img);
fclose(card);
}