改错题 下列给定程序中,函数fun的功能是:将字符串tt中的小写字母都改成对应的大写字母,其他字符不变,例如输入Ab,cD,则输出AB,CD。
请改正程序中的错误,使其能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题 程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
char *fun(char tt[])
{
int i;
/********found********/
for (i=0; tt[i]; i++)
if ((tt[i] >= 'a') || (tt[i]<='z'))
/********found********/
tt[i] += 32;
return (tt);
}
main()
{
char tt[81];
printf("\nPlease enter a string:");
gets(tt);
printf("\nThe result string is :\n%s", fun(tt));
}
第1处:if ((tt[i]>=’a’)||(tt[i]<=’z’))应改为if ((tt[i]>=’a’)&&(tt[i]<=’z’))
第2处:tt[i]+=32;应改为tt[i]-=32;