How do I write a simple regular expression pattern matching function in C or C++?

后端 未结 9 1127
我寻月下人不归
我寻月下人不归 2021-02-01 06:58

This is a question in my paper test today, the function signature is

int is_match(char* pattern,char* string)

The pattern is limited to only A

9条回答
  •  天命终不由人
    2021-02-01 07:31

    A C program to find the index,from where the sub-string in the main string is going to start. enter code here

    #include
    int mystrstr (const char *,const char *);
    int mystrcmp(char *,char *);
    int main()
    {
        char *s1,*s2;//enter the strings, s1 is main string and s2 is substring.
        printf("Index is %d\n",mystrstr(s1,s2));
        //print the index of the string if string is found
    }
    //search for the sub-string in the main string
    int mystrstr (const char *ps1,const char *ps2) 
    {
        int i=0,j=0,c=0,l,m;char *x,*y;
        x=ps1;
        y=ps2;
        while(*ps1++)i++;
        while(*ps2++)j++;
        ps1=x;
        ps2=y;
        char z[j];
        for(l=0;lps4[i])
            return +1;
        else
            return -1;
    }
    

提交回复
热议问题