模拟实现库函数strcpy
void my_strcpy(char* pstr, char str[])
{
int i = 0;
while (str[i] != '\0')
{
*pstr = str[i];
pstr++;
i++;
}
*pstr = '\0';
}
void main()
{
char str[10] = { 0 };
char str1[10] = { 0 };
strcpy(str, "你好");
printf("strcpy(str, %s) = %s\n", "你好", str);
my_strcpy(str1, "你好");
printf("my_strcpy(str1, %s) = %s", "你好", str1);
}
模拟实现库函数strlen
int my_strlen(char* pstr)
{
int count = 0;
while (*pstr != '\0')
{
count++;
pstr++;
}
return count;
}
void main()
{
char str[] = "123456";
printf("strlen(str) = %d\n", strlen(str));
printf("my_strlen(str) = %d\n", my_strlen(str));
}