1.模拟实现strlen
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
int MyStrlen(const char *str)
{
assert(str != NULL);
int count = 0;
while (*str)
{
count++;
str++;
}
return count;
}
int main()
{
char str[] = "hello tomorrow";
int count = MyStrlen(str);
printf("%d", count);
return 0;
}
2、模拟实现strcpy
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
void MyStrcpy(char* dest, const char* sor)
{
assert(dest != NULL && sor != NULL);
while (*sor)
{
*dest = *sor;
sor++;
dest++;
}
}
int main()
{
char sor[] = "hello tomorrow";
char dest[50] = {
0 };
MyStrcpy(dest, sor);
printf("%s", dest);
return 0