Example: In the following given program, the function of the function fun is to connect n (1≤n≤10) strings to form a new string and place it in the string pointed to by 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);
}
The output running window is as follows:
越努力越幸运!
加油,奥力给!!!