file - Endless while loop - C programming -


i tried create program compares between 2 files , checks if second file exist in first file. function r_scan gets endless loop. know why doesn't work?

this code:

    /**     function scan file , check if there virus in file.      input:     virus_address - address of virus file.     scaned_address - adress of file scan.     output:     end - if the file infected. 0 - infected, 1 - not infected.     **/     int r_scan(char* virus_address, char* scaned_address)     {         //init         char v = ' ', s = ' ';         int end = 1, = 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 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; } 

the manual page of fseek says:

a successful call fseek() function clears end-of-file indicator

when program loops, fseek(sp, seek, seek_set); called before feof(sp) why feof returns 0. , because not testing return value of fread(&s, 1, 1, sp); program loops forever.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -