首页 > 其他分享 >mystrcat

mystrcat

时间:2023-05-09 17:32:19浏览次数:29  
标签:p1 dest mystrcat len char source


#include"mystrcat.h"

char * mystrcat(char *dest,char *source)
{
	int len_dest = strlen(dest);
	int len_source = strlen(source);
	char *p1 = NULL;
	
	char *p = (char *)malloc((sizeof(char)*((len_dest+len_source)+1)));
	len_source = 0;
	p1 = p;
	if(NULL == p)
	{
		perror("malloc !\n");
		exit(1);
	}
	else
	{
		while(dest[len_source]!='\0')
		{
			p[len_source]=dest[len_source];
			len_source++;
		}
		p[len_source] = '\0';

		len_dest  = len_source;
		len_source = 0;

		while(source[len_source]!='\0')
		{
			p[len_dest]=source[len_source];
			len_source ++;
			len_dest++;
		}
		p[len_dest] = '\0';
	}
	return p1;
}
int main()
{
	char *p1 = "myname";
	char *p2 = "isme";
	char *m;
	
	m = mystrcat(p1,p2);
	printf("\t  after  mystrcat func call  is  %s\n",m);

	return 0;
}



欢迎指出bug~~~


标签:p1,dest,mystrcat,len,char,source
From: https://blog.51cto.com/u_16105066/6259506

相关文章