This is part of a C code. I need help to fix it.
This program checks if a file signature is in another file.
If it is, the function finds match then it returns 1
else it returns 0
.
The problem is that it always returns 0
even when it should return 1
.
This is the function I wrote:
int scanFile(char* file_name, FILE * virus_signature, long virus_size) //Scan the given file to see if he has the signature
{
FILE * file_for_scan = fopen(file_name, "rb");
char ch_temp, ch_temp2;
int i = 0;
fseek(virus_signature, 0, SEEK_SET);
while ((ch_temp = fgetc(file_for_scan)) != EOF)
{
if ((ch_temp2=fgetc(virus_signature)) == ch_temp)
{
i++;
if (i == virus_size)
{
fclose(file_for_scan);
return 1;
}
}
else
{
i = 0;
fseek(virus_signature, 0, SEEK_SET);
}
}
fclose(file_for_scan);
return 0;
}
Please help me fix my code.