Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions C/string_match_wildacards.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdbool.h>
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 ");

}