一、 填空题
请补充fun函数,该函数的功能是:删除字符数组中比指定字符小的字符,指定字符从键盘输入,结果仍保存在原数组中。
例如,输入“abcdefghij”,指定字符为’d’则结果输出“defghij”。
请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。
#include
#define N 80
void fun(char s[], char ch)
{
int i = 0, j = 0;
while (s[i])
{
if (s[i] < ch)
{
___1___;
}
else
{
___2___;
i++;
}
}
___3___;
}
main()
{
char str[N], ch;
printf("\n Input a string:\n");
gets(str);
printf("\n******** original string ********\n");
puts(str);
printf("\n Input a character :\n");
scanf("%c", &ch);
fun(str, ch);
printf("\n******** new string ********\n");
puts(str);
}
答案:
1、i++ 或 ++i 或 i+=1 或 i=i+1
2、s[j++]=s[i]
3、s[j]=’\0’ 或s[j]=0
编辑特别推荐: