字符串查找相同字母代码

int char_contains(char str[],char c)
{
    //方法1:
    int len=strlen(str);
    for (int i=0; i<len; i++)
    {
        if (str[i]==c)
        {
            return 1;
        }
    }
    return 0;
    //方法2:
    int i=0;
    while (str[i]!='\0')
    {
        if (str[i]==c)
        {
            return 1
;
        }
        i++;
    }

    return 0;
    //方法3:
    int i=-1;
    while (str[++i]!='\0')
    {
        if (str[i]==c)
        {
            return 1
;
        }
    }

    //方法4:
    while (str[++i]!='\0'&&str[i]!=c);

     //return str[i] == ‘\0’?0:1;
    return str[i]!=‘\0';
}

posted on 2014-09-14 19:24  安琪  阅读(290)  评论(0编辑  收藏  举报

导航