performance – Check if a given string matches a wildcard pattern

Move your main() to the bottom, so you don’t have to declare other functions, it’s also less prone to errors.

'*' is not called a star, but it’s called an asterisk.

Instead of using an additional function for hiding the argument int star, which acts as a memory, reduce to only one function and use a static int star as a function variable within that function.

I find your approach of a self calling recursive function interesting. You should make sure that it becomes never to an infinity loop, by counting each calls, probably within another static int function variable.

Please add some more comments, especially about the functionality of your function.

PS What happens when your search pattern argument begins with an asterisk, like "*a*b*c"?

PPS if your goal is to achieve the most performant solution, a self calling recursive function is not the fastest way to accomplish. Using a clever loop would be faster, you might even just use a goto to jump back to your function top line.

Example:

#include <stdio.h>
#include <string.h>


int compareStrings(char *s, char *regex)
{
    static int star = 0;
    
    START:
    if (*s == '' && *regex == '')
    {
        return 1;
    } else if (*regex == '*')
    {
        //return compareHelper(s, regex + 1, 1); // star is seen hence will be set to true.
        regex++;
        star = 1;
        goto START;
    } else
    {
        if (!star)
        {
            if (*s != *regex)
            { // star was not seen and they differ in char
                return 0;
            } else
            {
                //return compareHelper(s + 1, regex + 1, star);
                s++;
                regex++;
                goto START;
            }

        } else
        {
            while (*s && *s != *regex)
            {
                s++;
            }
            if (*s == '') return 0;
            else
            {
                //I'm pretty sure your return statement can be reduced to a more elementar statement.
                //PS I'm not reducing it for you.
                //return compareStrings(s + 1, regex + 1, 0) | compareStrings(s + 1, regex, 1);
                star = 0;
                int a = compareStrings(s + 1, regex + 1);
                star = 1;
                int b = compareStrings(s + 1, regex);
                
                return a | b;
            }
        }
    }
}

int main()
{
    printf("%dn", compareStrings("aaaacbbb", "a*b"));
    printf("%dn", compareStrings("aaaabccccccccb", "a*b*c"));
    return 0;

}

PPPS please rethink about that statement: return compareStrings(s + 1, regex + 1, 0) | compareStrings(s + 1, regex, 1);, it probably can be simplified.