* 可以匹配0个或0个以上的字符
?可以匹配一个字符
bool match(char *pattern, char *content) {
// if we reatch both end of two string, we are done
if ('\0' == *pattern && '\0' == *content)
return true;
/* make sure that the characters after '*' are present in second string.
this function assumes that the first string will not contain two
consecutive '*'*/
if ('*' == *pattern && '\0' != *(pattern + 1) && '\0' == *content)
return false;
// if the first string contains '?', or current characters of both
// strings match
if ('?' == *pattern || *pattern == *content)
return match(pattern + 1, content + 1);
/* if there is *, then there are two possibilities
a) We consider current character of second string
b) We ignore current character of second string.*/
if ('*' == *pattern)
return match(pattern + 1, content) || match(pattern, content + 1);
return false;
}