例題:下列給定程式中,函式fun的功能是:將n(1≤n≤10)個字串連接起來,組成一個新串,放在s所指字串中,
例如,把2個字串as、df連接起來,結果是asdf,
注意:不要改動main函式,不能增行或刪行,也不能更改程式的結構,
代碼如下:
#include<conio.h>
#include<stdio.h>
#include<string.h>
void fun(char str[][10],int m,char*s)
{
int j,q,i;
for(j=0;j<m;j++)
{
q=strlen(str[j]);
for(i=0;i<q;i++)
s[i]=str[j][i];
s+=q;
s[0]=0;
}
}
main()
{
int n,t;
char s[10][10],p[120];
printf("\nPlease enter n:");
scanf("%d",&n);
gets(s[0]);
printf("\nPlease enter %d string:\n",n);
for(t=0;t<n;t++)
gets(s[t]);
fun(s,n,p);
printf("\nThe result is :%s\n",p);
}
輸出運行視窗如下:

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