strcat函数
【摘要】 #include <stdio.h> char* strcat(char *dest, const char *src){//注意*号的位置,紧挨着char,表示返回一个char*型的指针,而紧挨着参数名,表示该参数是一个指针,便于程序的理解。 char *address = dest; if (dest == NULL && src == NUL...
-
#include <stdio.h>
-
-
char* strcat(char *dest, const char *src)
-
{//注意*号的位置,紧挨着char,表示返回一个char*型的指针,而紧挨着参数名,表示该参数是一个指针,便于程序的理解。
-
char *address = dest;
-
if (dest == NULL && src == NULL)
-
{
-
return dest;
-
}
-
-
while (*dest != '\0')
-
{
-
dest++;
-
}
-
-
while ((*dest++ = *src++) != '\0');
-
-
return address;
-
}
-
-
int main()
-
{
-
char a[100] = "abcdefgihklmn";
-
char b[100] = "\0opqrstuvwxyz";
-
mystrcat(a,b);
-
printf("%s\n",a);
-
return 0;
-
}
-
//linux源码
-
/**
-
* strcat - Append one %NUL-terminated string to another
-
* @dest: The string to be appended to
-
* @src: The string to append to it
-
*/
-
/*
-
char *strcat(char *dest, const char *src)
-
{
-
char *tmp = dest;
-
-
while (*dest)
-
dest++;
-
while ((*dest++ = *src++) != '\0')
-
;
-
return tmp;
-
}
-
/***
-
*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;
-
-
while( *cp )
-
cp++; /* find end of dst */
-
-
while( *cp++ = *src++ ) ; /* Copy src to end of dst */
-
-
return( dst ); /* return dst */
-
-
}
-
//汇编源码
-
char *strcat(char *dest, const char *src)
-
{
-
__asm
-
{
-
mov eax, dest
-
mov edx, src
-
Handlefordest:
-
mov ecx, DWORD PTR[eax]
-
cmp ecx, 0
-
je Begin
-
inc eax
-
jmp Handlefordest
-
-
Begin:
-
mov ecx, DWORD PTR [edx]
-
cmp ecx, 0
-
je End
-
mov DWORD PTR [eax], ecx
-
inc eax
-
inc edx
-
jmp Begin
-
End:
-
mov DWORD PTR [eax], 0
-
mov eax, dest
-
}
-
}
文章来源: blog.csdn.net,作者:悦来客栈的老板,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq523176585/article/details/11888585
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)