例題:下列給定程式中,函式fun的功能是:從N個字串中找出最長的字串,并將其地址作為函式值回傳,各字串在主函式中輸入,并放入一個字串陣列中,
注意:不要改動main函式,不能增行或刪行,也不能更改程式的結構,
代碼如下:
#include<stdio.h>
#include<string.h>
#define N 5
#define M 81
char*fun(char(*q)[M])
{
int i;
char*p;
p=q[0];
for(i=0;i<N;i++)
if(strlen(p)<strlen(q[i]))
p=q[i];
return p;
}
main()
{
char s[N][M],*longest;
int i;
printf("Enter %d line:\n",N);
for(i=0;i<N;i++)
gets(s[i]);
printf("\nThe N string:\n",N);
for(i=0;i<N;i++)
puts(s[i]);
longest=fun(s);
printf("\nThe longest string:\n");
puts(longest);
}
輸出運行視窗如下:

越努力越幸運!
加油,奧力給!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/252132.html
標籤:其他
上一篇:模擬搜索框
下一篇:Windows快捷鍵精華版
