Account for needles that end in a *

This commit is contained in:
Nick Chambers 2022-01-14 10:19:31 -06:00
parent 201e9b0eae
commit a573539ac8
1 changed files with 6 additions and 2 deletions

View File

@ -4,7 +4,7 @@ int match(const char *needle, const char *haystack) {
needle += 1; needle += 1;
} else if(*needle == '*') { } else if(*needle == '*') {
if(*(needle + 1) == '\0') { if(*(needle + 1) == '\0') {
return 0; return 1;
} else if(*(needle + 1) == *haystack) { } else if(*(needle + 1) == *haystack) {
needle += 1; needle += 1;
} else { } else {
@ -14,10 +14,14 @@ int match(const char *needle, const char *haystack) {
needle += 1; needle += 1;
haystack += 1; haystack += 1;
} else { } else {
return 1; return 0;
} }
} }
while(*needle == '*') {
needle += 1;
}
return *needle == '\0'; return *needle == '\0';
} }