#include <stdio.h>
#include <stdint.h>
typedef uint8_t BYTE;
int main(int argc, char* argv[])
{
// checks proper user input on command line
if (argc != 2)
{
fprintf(stderr, "Usage: ./recover image\n");
return 1;
}
// opens .raw file and checks for errors
FILE *inptr = fopen(argv[1], "r");
if (inptr == NULL)
{
fprintf(stderr, "Could not open file\n");
return 2;
}
// creates buffer to store 512 bytes
BYTE buffer[512];
// keeps track of jpegs found
int jpegCount = 0;
// initializes filename and file variables for writing
char filename[8];
FILE *currentjpeg;
// repeats until EOF
while (fread(buffer, 1, sizeof(buffer), inptr) == 512)
{
// do stuff
}
fclose(inptr);
}
The debugger says fread returns 0 on the while condition (I checked by making a few variables) and I don't understand why.