填空题
请补充main函数,该函数的功能是:从键盘输入一个字符串及一个指定字符,然后把这个字符及其后面的所有字符全部删除。结果仍然保存在原串中。
例如,输入“abcdef”,指定字符为‘e’,则输出“abcd”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio. h>
#define N 80
main ()
int i=0;
char str [N];
char ch;
clrscr ();
printf"/n Input a string:/n");
gets (str);
printf("kn Input a charator;/n");
scanf ("%c", &ch);
while (str [i] !='/0')
if (str [i]==ch)
【1】
【2】 ;
str[i]= 【3】 ;
printf"/n*** display string ***/n");
puts (str);
【正确答案】
1、[1] break; [2] i++ [3] '/0'
【答案解析】[解析] 填空1:while循环的作用是找到字符串srt中与指定字符ch相同的字符。当找到的时候,就使用break语句跳出循环。填空2:通过i++依次访问字符小str中的各个字符。填空3:在字符串str中与指定字符ch相同的字符位置上赋值‘/0’,这样输出字符中srt时,就不会输出指定字符及其后面的所有字符了。