为什么用指针就可以,有字符串就不行了?

img


void delchar( char *str, char c )
{
    int i=0;char b[99];
    while(*str!='\0')
    {
        if(*str!=c)
        {
            b[i++]=*str;
        }
        str++;
    }
    b[i+1]='\0';
}

```c
void delchar( char *str, char c ){
    char *s;
    s=str;
    while (*str!='\0') {
        if(*str!=c){
            *s++=*str;
        }
        str++;
    }
    *s=*str;
}

```

使用指针可以是因为指针指向的位置一样,所以取到的内容一样;第一个不可以是因为你只是使用了删除后把值赋值给了b数组,并没有改变str指向的值