From a573539ac8ec00d73bafd4cb2037074bd8bdb793 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Fri, 14 Jan 2022 10:19:31 -0600 Subject: [PATCH] Account for needles that end in a * --- c/cosmic.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/c/cosmic.c b/c/cosmic.c index bcc6123..391d934 100644 --- a/c/cosmic.c +++ b/c/cosmic.c @@ -4,7 +4,7 @@ int match(const char *needle, const char *haystack) { needle += 1; } else if(*needle == '*') { if(*(needle + 1) == '\0') { - return 0; + return 1; } else if(*(needle + 1) == *haystack) { needle += 1; } else { @@ -14,10 +14,14 @@ int match(const char *needle, const char *haystack) { needle += 1; haystack += 1; } else { - return 1; + return 0; } } + while(*needle == '*') { + needle += 1; + } + return *needle == '\0'; }