I'm trying to read characters from a binary file and compare them to characters from another binary file, but I want to start reading one of the files from the middle, not the beginning. When I try it, I can't read the file I'm trying to read from the middle because it immediately returns EOF. I tried to read it from different points, even moving the stream just a single place but it still returned EOF straight away.
int scanWithOffset(FILE* fc, FILE* fv, int start, int end)
{
int charRead1 = 0, charRead2 = 0, matchCounter = 0, match = 0;
int fileSize = findFileSize(fv);
int counter = 0;
if (!fseek(fc, start, SEEK_SET))
{
while (((charRead2 = fgetc(fv)) != EOF) && ((charRead1 = fgetc(fc)) != EOF)
&& !match && counter < (end - start))
{
counter++;
if (charRead1 == charRead2)
{
matchCounter++;
if (matchCounter == fileSize)
{
match = 1;
fclose(fc);
}
}
else
{
// if something doesn't match up, reset the counter and bring
// the stream back to the beginning
matchCounter = 0;
fseek(fv, 0, SEEK_SET);
}
}
if (!match)
{
fclose(fc);
}
}
return match;
}
fseekalltogether? - JabberwockyscanWithOffsetwithstart = 0? - JabberwockyEOFsignal. Could potentialy be eitherfgetc(fc)orfgetc(fv)... maybe printferror(fv)? - pmg