编程菜鸟的日记-初学尝试编程-编写函数实现strcat

#include <iostream>
using namespace std;
char *mystrcat(const char *str1,const char *str2)
{
 char *dst;
 dst=(char *)malloc(sizeof(str1)+sizeof(str2));
 char *start=dst;
 while(*dst=*str1)
 {
  dst++;
  str1++;
 }
 while(*dst=*str2)
 {
  dst++;
  str2++;
 }
 *dst='\0';
 return start;
}
void main()
{
 char str1[]=" ";
 char str2[]="abc";
 char *a=mystrcat(str1,str2);
 cout<<a<<endl;
 system("pause");
}

posted @ 2013-11-06 10:21  编程的爬行者  阅读(194)  评论(0编辑  收藏  举报