Take a moment to recall the implementation of the library function strcat, and also recall the operation of the pointer. The essence of the C language is the pointer, which makes people love and hate ... haha
#include<stdio.h>
char *mystrcat(char *dest,const char *src)
{
char *pTemp;
if((NULL == dest) || (NULL == src))
{
printf("the address is NULL,please check it!\n");
return NULL;
}
pTemp = dest;
while(*dest != '\0')
{
dest++;
}
while(*src != '\0')
{
*dest = *src;
dest++;
src++;
}
return dest;
}
int main(int argc,char argv[])
{
char *pCh = "hello";
char ch[50] = "world";
mystrcat(ch,pCh);
printf("%s\n",ch);
return 0;
}
First recall a strcat that can do basic work, followed by a little improvement and optimization ...