一个函数返回值的问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 16:57:11
2. 改错题
下列给定程序中,函数fun()的作用是:将字符串tt中的小写字母都改为对应的大写字母,其他字符不变。例如,若输入"edS,dAd",则输出"EDS,DAD"。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
/**********************found***********************/
char fun(char tt[])
{
int i;
for(i=0;tt[i];i++)
{
/**********************found***********************/
if((tt[i]>='A')&&(tt[i]<= 'Z'))
tt[i]-=32;
}
return(tt);
}
void main()
{
char tt[81];
system("CLS");
printf("\nPlease enter a string: ");
gets(tt);
printf("\nThe result string is: \n%s",fun(tt));
}
2. 改错题
(1)错误:char fun(char tt[])
正确:char *fun(char tt[])
(2)错误:if((tt[i]>='A')&&(tt[i]<= 'Z'))

数组不能做参数或者是函数返回值,子函数里的参数char tt[]其实也只是数组的首地址而已.C语言规定死的。

PS:可以把数组封装成一个structure作为参数或者返回值进行传递