C语言编程>第二十周 ⑧ 下列给定程序中,函数fun的功能是:将n(1≤n≤10)个字符串连接起来,组成一个新串,放在s所指字符串中。

例题:下列给定程序中,函数fun的功能是:将n(1≤n≤10)个字符串连接起来,组成一个新串,放在s所指字符串中。

例如,把2个字符串as、df连接起来,结果是asdf。
注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。

代码如下:

#include
#include
#include
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);
}

输出运行窗口如下:
C语言编程>第二十周 ⑧ 下列给定程序中,函数fun的功能是:将n(1≤n≤10)个字符串连接起来,组成一个新串,放在s所指字符串中。_第1张图片

越努力越幸运!
加油,奥力给!!!

你可能感兴趣的:(笔记)