給定程序MODI1.C中函數 fun 的功能是:判斷ch中的字符是否與str所指串中的某個字符相同; 若相同,什么也不做,若不同,則將其插在串的最后。 請改正程序中的錯誤,使它能進行正確的操作。 注意:不要改動 main 函數,不得增行或刪行,也不得更改程序的結構! 給定源程序:
#include<stdio.h>#include<string.h>voidfun(char str,char ch ){while(*str &&*str != ch ) str++;if(*str == ch ){ str [0]= ch;
str[1]='0';}}main(){char s[81], c ;printf("\nPlease enter a string:\n"); gets ( s );
printf ("\n Please enter the character to search : ");
c =getchar();fun(s, c);printf("\nThe result is %s\n", s);}
#include<string.h>#include<stdio.h>#define N 81
fun (char*s ){}main(){char a[N];
printf ("Enter a string : "); gets ( a );
printf ("The original string is : ");puts( a );
fun ( a );printf("\n");
printf ("The string after modified : ");
puts ( a );NONO();}