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
Post a Comment