c - How would i Use strtok to compare word by word -


i've been reading on strtok , thought best way me compare 2 files word word. far can't figure out how though

here function perfoms it:

int wordcmp(file *fp1, file *fp2) {    char *s1;    char *s2;    char *tok;    char *tok2;    char line[bufsize];    char line2[bufsize];    char comp1[bufsize];    char comp2[bufsize];    char temp[bufsize];    int word = 1;    size_t = 0;  while((s1 = fgets(line,bufsize, fp1)) && (s2 = fgets(line2,bufsize, fp2))) {     ; }  tok = strtok(line, " "); tok2 = strtok(line, " ");  while(tok != null) {     tok = strtok (null, " ");  }   return 0; } 

don't mind unused variables, i've been @ 3 hours , have tried possible ways can think of compare values of first , second strtok. know how check file reaches eof first.

when tried

  if(s1 == eof && s2 != eof)   {       return -1;   } 

it returns -1 when files same! because in order reach if statement outside of loop both files have reached eof makes program go if statement?

thanks in advance!

if want check if files same try doing,

    {        s1 = fgetc(fp1);        s2 = fgetc(fp2);         if (s1 == s2) {             if (s1 == eof) {                 return 1; // return true             }             continue;       }       else {         return -1;  // return false       }    } while (1); 

good luck :)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -