From c490aab853700e9946be62134b1abacf8ce340e0 Mon Sep 17 00:00:00 2001 From: Dennis thomas <52597699+denz647@users.noreply.github.com> Date: Wed, 20 Oct 2021 12:43:10 +0530 Subject: [PATCH] Add files via upload String match wildcards using dynamic programming --- C/string_match_wildacards.c | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 C/string_match_wildacards.c diff --git a/C/string_match_wildacards.c b/C/string_match_wildacards.c new file mode 100644 index 0000000..7806615 --- /dev/null +++ b/C/string_match_wildacards.c @@ -0,0 +1,40 @@ +#include +#include +bool check(char *str1, char * str2) ;// declaration of the check() function +int main() +{ + char str1[100],str2[100]; + printf("Enter first string with wild characters : "); + gets(str1); + printf("Enter second string without wild characters : "); + gets(str2); + test(str1,str2); + return 0; +} + +bool check(char *str1, char * str2) +{ + // checking end of both the strings + if (*str1 == '\0' && *str2 == '\0') + return true; + + // comparing the characters of both the strings and wild characters(*) + if (*str1 == '*' && *(str1+1) != '\0' && *str2 == '\0') + return false; + + // checking wild characters(?) + if (*str1 == '?' || *str1 == *str2) + return check(str1+1, str2+1); + + + if (*str1 == '*') + return check(str1+1, str2) || check(str1, str2+1); + return false; +} + +// test() function for running test cases +void test(char *str1, char *str2) +{ + check(str1, str2)? puts(" Yes "): puts(" No "); + +} \ No newline at end of file