C语言编程>第二十三周 ④ 请补充fun 函数,该函数的功能是:删除字符数组中比指定字符小的字符,指定字符从键盘输入,结果仍保存在原数组中。

例题:请补充fun 函数,该函数的功能是:删除字符数组中比指定字符小的字符,指定字符从键盘输入,结果仍保存在原数组中。

例如,输入 “asdfghj”,指定字符为 “f”,则结果输出 “sfghj”。
请勿改动主函数main与其它函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。

代码如下:

#include<stdio.h>
#define N 100
void fun(char s[],char ch)
{
    
    
	int i=0,j=0;
	while(s[i])
	{
    
    
		if(s[i]<ch)
		{
    
    
			i++;
		}
		else
		{
    
    
			s[j++]=s[i];
			i++;
		}
	}
	s[j]='\0';
}
main()
{
    
    
	char str[N],ch;
	printf("Please input a string:");
	gets(str);
	printf("\nThe original string:");
	puts(str);
	printf("\nPlease input a character:");
	scanf("%c",&ch);
	fun(str,ch);
	printf("\nThe new string:");
	puts(str);
}

输出运行窗口如下:
在这里插入图片描述

越努力越幸运!
加油,奥力给!!!

猜你喜欢

转载自blog.csdn.net/qq_45385706/article/details/113092674