0

that is the code I wrote can anyone tell what is wrong with my code!!

FILE *file = fopen(argv[1], "rb");
FILE *outptr = fopen("000.jpg", "wb");

typedef uint8_t BYTE;
BYTE buffer[512];

//Check that file open
if (file == NULL)
{
    printf("File Can't be open\n");
    return 1;
}
else
{
    while (fread(&buffer, sizeof(BYTE), 512, file) == 512)
    {
        if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff)
        {
            fwrite(&buffer , sizeof(BYTE), 512, outptr);
            fclose(file);
            fclose(outptr);
            return 0;
        }
    }
    fclose(file);
    fclose(outptr);
    return 0;
}
1
  1. A jpeg signature is 4 bytes; program only tests 3.
  2. Program only writes one 512-byte block.

You must log in to answer this question.

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