测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A36817. 请编写一个函数fun,函数的功能是删除字符串中的所有空格。例如,主函数中输入"asd af aa 267",则输出为"asdafaaz67"请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include <stdio.h>#include <stdlib.h>#include <ctype.h>void fun(char *str){ int i=0…

填空题 困难

题目描述

请编写一个函数fun,函数的功能是删除字符串中的所有空格。

例如,主函数中输入"asd af aa 267",则输出为"asdafaaz67"

请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

void fun(char *str)

{

    int i=0;

    char *p=str;

    while(①)

    {

      if(②)

      {

        ③

      }

      ④

    }

    ⑤

}

main()

{

    char str[81];

    void NONO ();

    printf("Input a string:");

    gets(str);

    puts(str);

    fun(str);

    printf("*** str:%s\n",str);

    NONO();

}

void NONO ()

{/* 请在此函数内打开文件,输入调试数据,

 调用 fun 函数,输出数据,关闭文件。 */

    char str[81];

    int n=0;

    FILE *rf, *wf;

    rf=fopen("in.dat","r");

    wf=fopen("out.dat","w");

    while(n<8) 

    {

        fgets(str, 80, rf);

        fun(str);

        fprintf(wf, "%s", str);

        n++;

    }

    fclose(rf);

    fclose(wf);

    system("pause");

}

参考答案

<p>1. 正确答案: *p</p><p>2. 正确答案: *p!=' '</p><p>3. 正确答案: str[i++]=*p</p><p>4. 正确答案: p++;</p><p>5. 正确答案: str[i]='\0';</p>
上一题 下一题