c/cosmic.c: A barebones globals implementation

This commit is contained in:
Nick Chambers 2022-01-13 12:35:48 -06:00
parent 7da798d8fa
commit a4000ec9b3
1 changed files with 32 additions and 0 deletions

32
c/cosmic.c Normal file
View File

@ -0,0 +1,32 @@
#include <stdio.h>
int match(const char *needle, const char *haystack) {
while(*haystack) {
if(*needle == '*' && *(needle + 1) == '*') {
needle += 1;
} else if(*needle == '*') {
if(*(needle + 1) == '\0') {
return 0;
} else if(*(needle + 1) == *haystack) {
needle += 1;
} else {
haystack += 1;
}
} else if(*needle == *haystack) {
needle += 1;
haystack += 1;
} else {
return 1;
}
}
return *needle != '\0';
}
int main(int argc, char **argv) {
if(argc != 3) {
return 1;
}
return match(argv[1], argv[2]);
}