将程序补充完整,实现功能:输入2个字符串,判断两个串是否相同,相同输出yes,不同输出no。 #include
本程序中,函数fun的功能是判断字符串是否是回文,若是回文,则返回1,主函数中输出YES;否则,函数返回0,主函数中输出NO。回文是指顺读和倒读都一样的字符串。例如,字符串LEVEL是回文,而123312就不是回文。请在函数fun的花括号中填入你编写的若干语句。(注意:不改动程序的结构,不得增行或删行。)
#include
#define N 80
int fun (char *str)
{
}
main()
{ char s[N];
printf(“Enter a string : ”) ;
gets (s) ;
printf(“\n\n”) ;
puts (s) ;
if (fun (s))
printf (“YES\n”) ;
else
printf (“N0\n”) ;
nono ();
}
nono ()
{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件.*/
int i;
FILE *rf, *wf ;
char s[N] ;
rf = fopen (“bc.in”,“r”) ;
wf = fopen (“bc.out”,“w”) ;
for (i=0; i<10; i++ )
{ fscanf (rf, “%s”,s ) ;
if (fun (s ))
fprintf (wf, “%s YES\n”, s ) ;
Else
fprintf(wf, “%s NO\n”, s ) ;
}
fclose (rf) ;
fclose (wf) ;
}
下列给定的程序中,函数proc的功能是:判断字符ch 是,与str所指字符串中的某个字符相同;若相同,则什么也不做,若不同,则将其插在串的最后。请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include include include include //****found**** void proc(char str,char ch) { while(*str &&*str!=ch)str++; //****found**** if(*str==ch) { str[0]=ch; //****found**** str[1]=0: } } void main { char str[81],ch; system("CLS"); printf("\nPlease enter a string:"); gets(str); printf("\n Please enter the character to search:"); ch=getchar; proc(str,ch); printf("\nThe result is%s\n",str); }
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!