c - comparing 2 char variables -


int compare (char * s, char * pre)  {     int x = 0;     char p;     char orig;     while (pre[x] != '\0')     {        printf("%c", tolower(pre[x]) );       printf("%c", tolower(s[x]) );       orig = tolower(s[x]);       p = tolower(s[x]);       if (orig != p);        {           return 0;       }        x++;     }      return 1; } 

expected return : 1 (values identical till end of loop) resulted return : 0 (values don't match)

this tautology:

orig = tolower(s[x]); p = tolower(s[x]); if( orig != p ) etc. 

probably? should be:

orig = tolower(s[x]); p = tolower(pre[x]); if( orig != p ) etc. 

note ; removed if stmt.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -