二、改錯題:給定程序MODI1.C中函數(shù)fun的功能是: 將s所指字符串中的字母轉(zhuǎn)換為按字母序列的后續(xù)字母(但Z轉(zhuǎn)換為A, z轉(zhuǎn)換為a),其它字符不變。
請改正函數(shù)fun中指定部位的錯誤, 使它能得出正確的結(jié)果。
注意: 不要改動main函數(shù), 不得增行或刪行, 也不得更改程序的結(jié)構(gòu)!
給定源程序:
#include
#include
void fun (char *s)
{
/**********found***********/
while(*s!='@')
{if(*s>='A' && *s<='Z' || *s>='a' && *s<='z')
{if(*s=='Z') *s='A';
else if(*s=='z') *s='a';
else *s += 1;
}
/**********found***********/
(*s)++;
}
}
main()
{char s[80];
printf("\n Enter a string with length < 80. :\n\n "); gets(s);
printf("\n The string : \n\n "); puts(s);
fun (s);
printf ("\n\n The Cords :\n\n "); puts(s);
}
解題答案:
/**********found***********/
while(*s)
/**********found***********/
s++;
******************************************
相關(guān)推薦:
2011年計算機等級考試二級C語言上機題庫
2011計算機二級C語言學(xué)前自測題匯總
2011年3月計算機二級C語言試題答案及解析匯總