#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~~~