填空题
下列给定程序中,函数proc()的功能是:从N个字符串中找出最长的那个串,并将其地址作为函数值返回。各字符串在主函数中输入,并放入一个字符串数组中。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<string.h>
#include<stdio.h>
#define N 5
#define M 81
//****found****
proc(char(*sq)[N])
{
int i;char*sp;
sp=sq[0];
for(i=0;i<N;i++)
if(strlen(sp)<strlen(sq[i]))
sp=sq[i];
//****found****
return sq;
}
void main()
{
char str[N][M],*longest;int i;
printf("Enter%d lines:/n",N);
for(i=0:i<N;i++)gets(str[i]);
printf("/nThe%d string:/n",N);
for(i=0;i<N;i++)puts(str[i]);
longest=proc(str);
printf("/nThe longest string:/n");
puts(longest);
}