C语言学习|字符串习题(10.20)

在字符串中删除与某字符相同的字符

char *DeleteStr (char s[],char c)
{
    int i,j = 0;
    for (i = 0; s[i] != '\0'; i++)
        if (s[i] != c)
        {
            s[j] = s[i];
            j++;
        }
    s[j] = '\0';
    return s;
}
char *DeleteStr (char *s,char c)
{
    char str[N];
    char *t = str;
    strcpy(t,s);
    for (; *t != '\0'; t++)
        if (*t != c)
        {
            *s = *t;
            s++;
        }
    *s = '\0';
    return s;
}

猜你喜欢

转载自blog.csdn.net/qq_42272723/article/details/83217679