Я попытался создать программу, которая сравнивает между 2 файлами и проверяет, существует ли второй файл в первом файле. Функция r_scan попадает в бесконечный цикл. Кто-то знает, почему это не работает?Endless while loop - программирование на C
Это мой код:
/**
The function scan the file and check if there is a virus in the file.
Input:
virus_address - The address of the virus file.
scaned_address - The adress of the file that we scan.
Output:
end - If the the file infected. 0 - infected, 1 - not infected.
**/
int r_scan(char* virus_address, char* scaned_address)
{
//INIT
char v = ' ', s = ' ';
int end = 1, i = 0;
long seek = 0;
FILE* vp = NULL;
FILE* sp = NULL;
//Open th5e files.
vp = fopen(virus_address, "rb");
sp = fopen(scaned_address, "rb");
fseek(vp, 0, SEEK_SET);
fseek(sp, 0, SEEK_SET);
//pre scanning
seek = 0;
//Check if the file infected.
while (!(feof(sp)) && end)
{
fread(&s, 1, 1, sp);
if (v == s)
{
v = fgetc(vp);
}
else
{
seek++;
fseek(vp, 0, SEEK_SET);
fseek(sp, seek, SEEK_SET);
fread(&v, 1, 1, vp);
}
if (v == EOF)
{
end = 0;
}
}
fclose(vp);
fclose(sp);
return end;
}
«Virus scanner»: D –
Что означает «предварительная проверка» с помощью 'fread (& s, 1, 1, sp),' mean? – VolAnd
ничего, что я просто забыл изменить. – liad