下列给定的程序中,函数fun()的功能是:判断字符ch是否与str所指字符串中的某个字符相同;若相同,则什么也不做,若相同,则将其插在申的最后。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
/*************found**************/
void fun (char str,char ch)
while (*str &&*str !=ch) str++;
/*************found**************/
if(*str==ch)
str[0]=ch;
/*************found**************/
str[1]=’0’;
main()
char s[81],c;
clrscr();
printf("\nPlease enter a strzng : ");
gets(s);
printf("\n Please enter the character to
search : ");
c=getchar();
fun(s,c);
printf("\nThe result is %s\n",s);