I can't figure out what's wrong with my code. File names are created successfully but all jpegs just show the corrupt thumbnail. I'm sure it has something to do with finding the start and end of the files. Here is a snippet from where i think my code is going wrong:
// Read each 512 bytes until end of file is reached
while (fread(&data, 512, 1, diskptr) == 1)
{
// Check for jpeg start
if (checkStart(data, jStart, jStartOE) == true)
{
jFound++;
writeJ(data, jFound - 1);
}
// If the first jpeg has already been found and current block is not
// the start of a file keep writing to the same file
else if (jFound > 0)
{
writeJ(data, jFound - 1);
}
}
checkStart() is just a function that looks for the four jpeg signature bytes in the start of a 512 block and returns true if it found them and false if it didn't.
writeJ() sprintfs a name respective to the current jFound number which is the amount of jpegs found. Then it opens a file with that name and the "a" argument. Then it writes 512 bytes from the data and finally closes the file.
Sometimes when I run the program two pictures show up fine for some strange reason, but then I run it again and they're gone.