改错
【要求】
1.打开T盘中的文件myf1c,按以下程序功能改正文件中程序的错误?
2.可以修改语句中的一部分内容,调整语句次序,增加少量的变量说明或编译预处理命令,但不能增加其他语句,也不能删去整条语句?
3.修改后的源程序仍保存在T盘myf1c中?
【程序功能】
下列程序中函数wordsearch的功能是将a指向的字符串中所有回文单词复制到b指向的二维数组中(一个回文单词存储在b数组的一行中),函数返回b数组中回文单词的个数?回文单词是指:一个单词自左向右读与自右向左读相同(字母不区分大小写)?例如,Dad是回文单词?
【测试数据与运行结果】
测试数据:Dadlefthomeatnoon.
屏幕输出:found 2 wordsDad
noon
【含有错误的源程序】
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
intwordsearch(chara[],charb[][10])
{ inti,j,k,m,n,t,c=0,d;for(i=0;a[i];i++)
{ for(j=i,k=i;isalpha(a[k]);k++);
m=j;n=k-1;
while(toupper(a[m])==toupper(a[n])&&m<=n)
{ m++;n--; }
if(m==n)
{ for(d=0,t=j;t<k;t++)
b[c][d]=a[t];
b[c][d]='/0';c++;
}
i=k;
}
returnc;
}
intmain()
{ chars1="Dadlefthomeatnoon.";chars2[10][10];
inti,j;puts(s1);
j=wordsearch(s1,s2);
printf("found %d words/n",j);
for(i=0;i<j;i++)
puts(s2);
getch();
return0;
}