strcpy的实现
断言
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
char * my_strcpy(char* dest, const char* src)
{
assert(src != NULL);//断言
assert(dest != NULL);//断言
char* ret = dest;
while (*dest++ = *src++)
{
;
}
return ret;// 返回目标空间的起始地址
}
int main()
{
char arr1[20] = "xxxxxxxxxxx";
char arr2[] = "hello";
printf("%s", my_strcpy(arr1, arr2));//链式访问
return 0;
}
strlen
断言
#include<assert.h>
#incldue<stdio.h>
unsigned int my_strlen(const char* arr)
{
assert(arr != NULL);
unsigned int i = 0;
while (*arr++ != '\0')
{
i++;
}
return i;
}
int main()
{
char arr[] = "hello world!";
printf("%d",my_strlen(arr));
return 0;
}