2016年8月3日 星期三

[C] Compare B string include in A string

#include <linux/kernel.h>

int compare (const char *s1, const char *s2)
{
    int count = 0;
    char t[1]= "\0";
    char *tmp = s1;

    while ( *s2 != '\0' )
    {
        sprintf(t,"%c",*s2);

        if (!strstr(s1,t))
        {
            return 1;
        }
        s2++;
    }
}

int main()
{
    int result;
    char a[12]="abcde";
    char b[12]="cef";

    result = compare(a, b);
    printf("result = %d\n",result);
}

0 意見:

張貼留言