Hello guys!
I wrote this program that compares two lines and says if they are equal or not. But there is a twist: A star can replace any character and even any Number of characters (like whole words).
My program nearly works. It returns everything correctly apart from when there is a mistake AFTER the star.
So:
Hello World
Hello World
= Match.
Hello World
H*o World
= Match.
Hello World
*World
= Match
But
Hello World
Hello W*sfd
Shows it matches, but it shouldnt!
Any help, tips, advice is appreciated.
Code:int match(char *s1, char *s2) { int s1length; int s2length; int is_match; int y; int x; int i; s1length = strlen(s1); s2length = strlen(s2); is_match = 0; y = 0; while (y < s1length) { i = y; if (s2[y] == '*') { while (s1[y] != s2[i + 1]) { if (s1[y] == '\0') { is_match = 1; break; } y++; } break; } if (s2[s2length - 1] == '*') { is_match = 1; break; } if (s1[y] == s2[y]) { is_match = 1; y++; continue; } else { is_match = 0; break; } } return (is_match); } int main() { int x; char array1[] = "Hello World"; char array2[] = "Hello W*ef"; x = match(array1, array2); printf("%d", x); return (0); }



LinkBack URL
About LinkBacks


