简答题
C语言
题号 #2257026
下列给定程序中,函数proc()的作用是:将字符串str 中的大写字母都改为对应的小写字母,其他字符不变。例如,若输入“abD,dFAD”,则输出“abd,dfad”。
请修改函数proc()中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构
试题程序:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
char*proc(char str[])
{
int I ;
for(1=0;str[1];I++)
//****found****
{
if(('A'<=str[I]||(str[I]<='Z'))
str[1]+=32;)
return(str);
}
void mare()
{
chin str[81];
syslem("CLS");
printf("\nPlease enter a string:");
gets(str);
printf("\nThe result string is:\n%s\n",proc
(str));
}
参考答案
暂无
答案解析
错误:if(('A'<=str[I]|| str[1]<='Z'))
正确:if((str[I]>='A')&&(str[I]<='Z '))
【解析】题目中要求将字符串str中所有的大写字母转化为对应的小写字母,判断一个字母为大写字母的条件为其ASCII码值大于字母A而且小于字母2。因此,“if(('A' <=str[I]||(str[I]<='Z '))”应改为“if((str[I]>='A') &&(str[I]<='Z '))”。

