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);
}

Related Posts:

  • [C] Get environment variable Embedded System armeb-unknown-linux-uclibcgnueabi-gcc env.c /*************************************************************************\ * … Read More
  • [C] Program Arguments #include <stdio.h> int main(int argc, char *argv[]) { int arg; for(arg = 0; arg < argc; arg++) { printf("arg = %d",arg); if(argv… Read More
  • C - pointerDescription : Pointer When I announce a variable " int *ptr."Ptr mean this is a address.This is a integer address.If I want assign a value, it must … Read More
  • [C] Copy file /*************************************************************************\ * Copyright (C) Michael Kerrisk, 2014. … Read More
  • [C] Make a temp file under /tmp /*************************************************************************\ * Copyright (C) Michael Kerrisk, 2014. … Read More

0 意見:

張貼留言