错的,这个str会后移,因此用str[i++]来定位第i个元素师错的。可以改成void fun(char *str) { char *p = str; while(*p) { if(*p!=' ')*str++ = *p; ++p; } *str = '\0';}
不对 一个指针不够 再加一个