0

is there a way to fread() the same bytes you just had read?

fread(buffer, 512, 1, inptr);
if (header(buffer) == true)
{
    //execute these lines

    do
    {
         //execute these lines
    }
    while (condition);
    
    fseek(inptr, 512, SEEK_SET);
}

I've tried to use fseek() but it goes start of the file. I want to rewind the fread() exactly 512 bytes back. Is this possible? Because do / while condition finishes when a image header spotted and main program goes back to reading but skips the part I've already read to check the image header, and as a result my program misses that header and skips that image. TIA

1 Answer 1

0
    fseek(inptr, -512, SEEK_CUR);

But why do you want to do this? There's no need in this program to manually move the pointer. What are you trying to do?

When you've read the 512 bytes into the header, they're available to both check for a signature and to write to the output file.

1
  • I've designed recover as shorter as possible. When the loop find the header it first writes a new jpeg until it founds another header. then writes a new jpeg. but when it read the header it has to leave the loop, so it skips the that 512 byte and reads another. So after finishing the jpeg writer loop it goes back and read that header again and goes back into the loop. This way I finish my program with 2 inner loops. hope I could express correctly
    – cetins
    Commented Oct 29, 2020 at 8:47

You must log in to answer this question.

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