0

I am stuck with my recover code. The compiler yells at me because I am doing a incompatible pointer to integer conversion but I can't see where...

recover.c:28:18: error: passing 'BYTE [512]' to parameter of type 'char *' converts between pointers to integer types with different sign
      [-Werror,-Wpointer-sign]

code

int main(int argc, char* argv[])
{    
// open file to recover
FILE *card = fopen("card.raw", "r");

if (card == NULL)
{
    printf("Could not open file. Retry!");
    return 2;
}

// declare buf
typedef uint8_t BYTE;
BYTE buf[512];

// read card in chunks of 512byte (FAT32 blocks)
while (fgets(buf, sizeof(buf), card) != NULL)
{
    fread(buf, 512, 1, card);

    if (buf[0] == 0xff && buf[1] == 0xd8 && buf[2] == 0xff && (buf[3] == 0xe0 || buf[3] == 0xe1))
    {
        int jpgnumber = 1;
        FILE *jpg = fopen(("%02d.jpg", jpgnumber), 'w');
        fwrite(&buf, 512, 1, jpg);
        fread(&buf, 512, 1, card);

        // !another jpg header
        while (buf[0] != 0xff && buf[1] != 0xd8 && buf[2] != 0xff && (buf[3] != 0xe0 || buf[3] != 0xe1))
        {
            fwrite(&buf, 512, 1, jpg);
            fread(&buf, 512, 1, card);
        }

        fclose(jpg);
        jpgnumber++;    
    }

}

fclose(card);
return 0;

}

1

The compiler doesn't like this:

        FILE *jpg = fopen(("%02d.jpg", jpgnumber), 'w');

Create a string variable, construct the filename in the string var using sprintf() and then use the string var in this command instead of ("%02d.jpg", jpgnumber).

You'll fix this error, but then the compiler will have some warnings when you compile. Because of the compiler flags, they'll appear as errors. Fix them and you'll be on your way.

If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)

You must log in to answer this question.

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