清全部空写法-C语言 [清字符串里面的全部空格]
自己看啦 不知道怎么说 反正代码里注释看的明白就明白了。
/* *时间: 2020年9月14日 11:23:49 *例: 清除字符串里面的空格。 *核心: 遇空格跳过 */ #include<stdio.h> void fun(char *str) { int i = 0; //i用来做重新赋值的下标 char *temp; //创建一个临时字符指针用来取str的字符; temp = str; while(*temp) { if(*temp != ' ') //如果temp取到的字符不等于空格 ,那就把取到的字母重新赋值给str[i]; {str[i] = *temp;i++;} temp++; //temp++ 取下一个字 } str[i] = '\0';//最后把str[i]添加结束标识'\0' } int main() { char str[20] = "a b c d e f g" ; fun(str); printf("%s",str); return 0; }