(This was also posted on reddit, but I think it's been lost, sorry)
Hi guys, currently doing recover.
I'm having trouble with using fclose on my output file pointer (jpegptr) - every time I try to compile I get this error:
recover2.c:72:24: error: variable 'jpegptr' is uninitialized when used here [-Werror,-Wuninitialized]
fclose(jpegptr);
^~~~~~~
recover2.c:37:18: note: initialize the variable 'jpegptr' to silence this warning
FILE* jpegptr;
My code is below. I feel like I'm trying to close the jpegptr before i've opened it, but i'm not sure how to fix it.
FILE* jpegptr;
if (block[0] == 0xff &&
block[1] == 0xd8 &&
block[2] == 0xff &&
(block[3] & 0xf0) == 0xe0)
{
if (inprogress == 0)
{
inprogress = 1;
sprintf(filename, "%03i.jpg", picno);
jpegptr = fopen(filename, "w");
if (jpegptr == NULL)
{
fprintf(stderr, "Output file cannot be made\n");
return 2;
}
}
else
{
fclose(jpegptr);
picno ++;
sprintf(filename, "%03i.jpg", picno);
jpegptr = fopen(filename, "w");
if (jpegptr == NULL)
{
fprintf(stderr, "Output file cannot be made\n");
return 2;
}
}
fwrite(block, sizeof(int), 512, jpegptr);
}
I'm sure that I could open jpegptr in main which might solve the issue, but then every-time i run the program i would get a jpeg file outputted automatically, even if no jpegs even existed on the card.