I am trying to ease into this pset and am having difficulty starting with the first step - locate 1st jpg, create and write. I think that once I have that figured out, I'll have an easier time building out the rest.
1) My code compiles, but produces nothing. 2) I think (I think) that I figured out the difference between sprint (create jpg) and fwrite (write jpg to file). 3) I think that I correctly open and close the card.raw and the new jpg 4) Based on Zamyla's directive, I think I have the order of operation in the loop Lots of thinking, but no certainties:) If anyone can advise on whether or not I'm on the right track, it'd be great. Thanks!
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef uint8_t BYTE;
BYTE buffer[512];
int counter= 0;
int main(int argc, char* argv[])
{
FILE* inptr = fopen("card raw", "r");
if (inptr == NULL)
{
printf("Could not open.\n");
return 2;
}
char write_jpg[4];
int counter=0;
FILE* jpg = fopen(write_jpg, "w");
while(fread(&buffer,512,1,inptr) != 0)
{
fread(&buffer,512,1,inptr);
if(buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] == 0xe0 || buffer[3] == 0xe1))
{
sprintf(write_jpg,"%03i.jpg",counter);
jpg = fopen(write_jpg, "w");
fwrite(&buffer, 512, 1, jpg);
fclose(jpg);
counter++;
}
}
fclose(inptr);
}