字符串链接和复制

 1 // char szAry[20], char* lpStr2 = "xx";
 2 char* MyStrcat2(char* lpStr1, const char* lpStr2)
 3 {
 4   char* lpStrTemp = lpStr1;
 5   while(*lpStrTemp)
 6     lpStrTemp++;
 7 
 8 
 9   while(*lpStrTemp++ = *lpStr2++);
10 
11   return lpStr1;
12 }
13 
14 char* MyStrcpy2(char* lpStr1, const char* lpStr2)
15 {
16   char* lpStrTemp = lpStr1;
17   
18   while(*lpStrTemp++ = *lpStr2++);
19   
20   return lpStr1;
21 }

调用

 1 int main(int argc, char* argv[])
 2 {
 3   char szDstStr[128]  = "Hello";
 4   char* lpStr2  = "World!";
 5   char* lpStr3 = "xx"; 
 6   
 7   
 8   cout << MyStrcat2(szDstStr, lpStr2) << endl;
 9   cout << MyStrcpy2(szDstStr, lpStr3) << endl;
10   
11   return 0;
12 }

 

posted @ 2012-12-01 01:00  _**  阅读(350)  评论(0编辑  收藏  举报