Life is Good.

Enhance Tech and English
随笔 - 65, 文章 - 20, 评论 - 21, 引用 - 0
数据加载中……

6 - strcat

/***
*char *strcat(dst, src) - concatenate (append) one string to another
*
*Purpose:
*       Concatenates src onto the end of dest.  Assumes enough
*       space in dest.
*
*Entry:
*       char *dst - string to which "src" is to be appended
*       const char *src - string to be appended to the end of "dst"
*
*Exit:
*       The address of "dst"
*
*Exceptions:
*
******************************************************************************
*/

char * __cdecl strcat (
        
char * dst,
        
const char * src
        )
{
        
char * cp = dst; // 得到首地址, 然后遍历到最后, 再copy

        
while*cp )
                cp
++;                   /* find end of dst */

        
while*cp++ = *src++ ) ;       /* Copy src to end of dst */

        
return( dst );                  /* return dst */

}

int _tmain(int argc, _TCHAR* argv[])

  
char s1[] = "abc";
  
char s2[] = "def";
  
char* p = my_strcat(s1, s2);

  
return 0;
}

posted on 2011-06-02 22:18 Mike Song 阅读(209) 评论(0)  编辑 收藏 引用 所属分类: C字符串函数源码分析


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理