27. 编写函数fun,函数的功能是:从字符串中删除指定的字符。

1. 编写函数fun,函数的功能是:从字符串中删除指定的字符。同一字母的大、小写按不同字符处理。若程序执行时,输入字符串为:turbo c and borland c++,从键盘上输入字符:n,则输出后变为:turbo c ad borlad c++,如果输入的字符字符串中不存在,则字符串照原样输出。
注意:部分源程序存在考生文件夹下的文件prog5.c中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int fun(char s[],int c)
{
}
main()
{
static char str[]="turbo c and borland c++";
char ch;
system("cls");
printf("原始字符串:%s\n",str);
printf("输入一个字符:");
scanf("%c",&ch);
fun(str,ch);
printf("str[]=%s\n",str);
NONO();
}
NONO( )
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,
输出数据,关闭文件。 */
int j;
char ch,str1[100];
FILE *rf, *wf ;
char str[]="turbo c and borland c++";
rf = fopen("b13.in", "r") ;
wf = fopen("b13.out", "w") ;
strcpy(str1,str);
for (j=0;j<4;j++)
{ fscanf(rf,"%c",&ch);
strcpy(str,str1);
fun(str,ch);
fprintf(wf,"str[]=%s\n",str);
}
fclose(rf) ;
fclose(wf) ;
}

int fun(char s[],int c)
{

    int i,j=0;

    for(i=0;s[i]!='\0';i++)

        if(s[i]!=c)

        {

             s[j]=s[i];

             j++;

        }

    s[j]='\0';

    return 0;
}

加上其它代码,运行结果:

温馨提示:答案为网友推荐,仅供参考
相似回答