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