例題:下列給定程式中,函式fun的功能是:比較兩個字串,將長的字串的首地址作為函式值回傳,
例如,輸入 兩串字符分別為“asdf”和"asdfg",則輸出為 “asdfg”,
注意:不要改動main函式,不能增行或刪行,也不能更改程式的結構,
代碼如下:
#include<conio.h>
#include<stdio.h>
char*fun(char*s,char*t)
{
int s1=0,t1=0;
char*str1,*str2;
str1=s;
str2=t;
while(*str1)
{
s1++;
str1++;
}
while(*str2)
{
t1++;
str2++;
}
if(t1>s1)
return t;
else
return s;
}
main()
{
char p[80],q[80];
printf("\nEnter a string: ");
gets(p);
printf("\nEnter another string:");
gets(q);
printf("\nThe longer is:%s\n",fun(p,q));
}
輸出運行視窗如下:

越努力越幸運!
加油,奧力給!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/253088.html
標籤:其他
