It compiles. But if I step into this function: fread(&pos, sizeof(BYTE), 1, file);
I get an error from GDB: _GI_IO_fread (buf=0xbfffff0d, size=1, count=1, fp=0x804b008) at iofread.c:35 iofread.c: No such file or directory.
It keeps saying: in iofread.c with different line numbers.
How can I read the infile? What am I doing wrong?
include
include
include "bmp.h"
int main(int argc, char* argv[])
{ // remember file name
char* infile = "card.raw";
// open CF card
FILE* file = fopen(infile, "r");
if (file == NULL)
{
printf("Could not open %s.\n", file);
fclose(file);
return 1;
}
// create storage for position
fpos_t pos;
// get current position
fgetpos(file, &pos);
// counter for the recovered photo's
int i = 000;
// read until JPEG is detected.
while (fgetpos(file, &pos) != EOF)
{
// read 1 byte
fread(&pos, sizeof(BYTE), 1, file);
// search
if (fgetpos(file, &pos) == 0xff)
{
// read 1 byte and adjust position
fread(&pos, sizeof(BYTE), 1, file);
fsetpos(file, &pos);
if ((fgetpos(file, &pos) + 1 == 0xd8) && (fgetpos(file, &pos) + 2 == 0xff)
&& (fgetpos(file, &pos) + 3 == 0xe0 || fgetpos(file, &pos) + 3 == 0xe1))
{
// create and open a JPEG
FILE* photo = fopen("[i].jpg", "w");
photo = malloc(513 * (sizeof(BYTE)));
// copy if malloc isn't NULL
if (photo != NULL)
{
// copy 512 bytes
for (int pixel = 0; pixel < 511; pixel++)
{
fread(&pos, sizeof(BYTE), 1, file);
fwrite(&pos, sizeof(BYTE), 1, photo);
fsetpos(file, &pos);
}
// close JPEG & adjust counter
free(photo);
fclose(photo);
i++;
}
}
}
// TODO: check if search continues
else
{
fsetpos(file, &pos);
}
}
// close card-file
fclose(file);
}