1.模拟实现strcpy
2.模拟实现strcat
#include<stdio.h>
#include <stdlib.h>
#include <assert.h>
char * my_strcpy(char* dst,const char* src)
{
assert(dst && src);
char * ret = dst;
while (*src!='\0')
{
*dst = *src;
dst++;
src++;
}
*dst = '\0';
return ret;
}
char * my_strcat(char* dst, const char* src)
{
assert(dst && src);
char * ret = dst;
while (*dst!='\0')
{
dst++;
}
while (*src != '\0')
{
*dst = *src;
dst++;
src++;
}
*dst = '\0';
return ret;
}
int main()
{
char arr1[] = "abc";
char arr2[10];
char arr3[20] = "ABC";
my_strcpy(arr2,arr1);
my_strcat(arr3, arr1);
printf("%s\n",arr2);
printf("%s\n", arr3);
system("pause");
return 0;
}