I cant understand why 049.jpg is not working
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
unsigned char bytes[512];
//counter for the jpg files
int jpgCount = 0;
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("Usage: ./recover image\n");
return 1;
}
// Open file which was provided in the command line
FILE *rawCard = fopen(argv[1], "r");
if (!rawCard)
{
return 1;
}
//Create pointer to new file
FILE *picFromCard = NULL;
//do untill end of file
while (!(feof(rawCard)))
{
//read 512 bytes and look for JPEG in first 4 bytes
fread(bytes, 512, 1, rawCard);
// Check first four bytes
if (bytes[0] == 0xff &&
bytes[1] == 0xd8 &&
bytes[2] == 0xff &&
(bytes[3] & 0xf0) == 0xe0)
{
//close any file that may be open or being written
if (picFromCard != NULL)
{
fclose(picFromCard);
}
//format the file name ###.jpg
char filename[3];
sprintf(filename, "%03i.jpg", jpgCount);
//open a new file for writting and check that it opened successfully
//"w" Creates an empty file for writing. If a file with the same name already exists,
//its content is erased and the file is considered as a new empty file.
//"w+" on the other hand creates an empty file for both reading and writing.
picFromCard = fopen(filename, "w+");
if (picFromCard == NULL)
{
fclose(rawCard);
fprintf(stderr, "Could not create \n");
return 1;
}
//write first block of 512 bytes to the file
fwrite(&bytes, 512, 1, picFromCard);
//Counter for the numbers of jpg files found and it will help in naming the file.
jpgCount++;
}
//when jpgCount is greater then 0 that means we already have a file found and so write remaining blocks of memory to the file.
else if (jpgCount > 0)
{
fwrite(&bytes, 512, 1, picFromCard);
}
else if (jpgCount > 0 && )
}
// Close files
fclose(rawCard);
fclose(picFromCard);
}