高仿模拟练习,补全 found 标记处空缺,答案点击按钮展开
删除字符串中的所有空格字符,其他字符保持顺序不变,请补全found处。
#include <stdio.h>
void fun(char *s)
{
char *p=s;
while(*s!='\0')
{
/**********found**********/
if(*s ___1___ ' ')
{
/**********found**********/
*p = ___2___;
p++;
}
/**********found**********/
___3___;
}
*p='\0';
}
int main()
{
char str[100];
gets(str);
fun(str);
printf("%s\n",str);
return 0;
}
!=
*s
s++
第1空判断当前字符不是空格;第2空将非空格字符复制到新位置;第3空源指针后移。输入hello world,输出helloworld。