0
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char *argv[])
{ typedef uint8_t BYTE;

FILE *file = fopen(argv[1], "r");
int counter=0;
FILE *img= NULL;
if (file ==NULL)
{
return 1;
 }
if (argc!=2)
{
return 2;
}
BYTE buffer[512];
char *filename= malloc(8*(sizeof(char)));
while (fread(buffer, 1, 512, file))
{
if (buffer[0]==0xff && buffer[1]==0xd8 && buffer[2]==0xff && (buffer[3]&0xf0)==0xe0)
{
sprintf(filename, "%03i.jpg", counter);
img= fopen(filename, "w");
counter++;
 if (img!=NULL)
{
fwrite(filename, sizeof(char) , 512, img);
}

 else
 {
return 1;
}
if (counter>0)
{
fclose(img);
 }
 }
  }
fclose(file);
free(filename);
 }

1 Answer 1

1

This program only writes the signature buffer to the jpg. This block

if (counter>0)
{
fclose(img);
 }

closes the image, and nothing is written until it finds another signature. That would probably be a good time to write the next buffer to the image. Program should not close the img until it is ready to start a new jpg.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .