二级C语言 程序填空题

高仿模拟练习,补全 found 标记处空缺,答案点击按钮展开

19程序填空题:删除字符串中的空格

删除字符串中的所有空格字符,其他字符保持顺序不变,请补全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;
}
参考答案
1: !=
2: *s
3: s++
解析

第1空判断当前字符不是空格;第2空将非空格字符复制到新位置;第3空源指针后移。输入hello world,输出helloworld。

试题及答案仅供练习参考,不保证完全准确,正式考试请以NCRE官方教材及官方内容为准。

©2026 NCRE二级题库 版权所有