#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
char *my_strcpy(char *str, const char *arr)
{
char *ret = str;
assert(str);
assert(arr);
while (*str++ = *arr++)
{
;
}
return ret;
}
int main()
{
char arr[] = "abcde";
char str[64];
my_strcpy(str, arr);
printf("%s\n", str);
system("pause");
return 0;
}
strcat
char *my_strcat(char *dest, const char*src)
{
char *ret = dest;
assert(dest != NULL);
assert(src != NULL);
while (*dest)
{
dest++;
}
while ((*dest++ = *src++))
{
;
}
return ret;
}
int main()
{
char arr[] = "abcde";
char str[]="1234";
my_strcat(str, arr);
printf("%s\n", str);
system("pause");
return 0;
}
strcmp
#include<stdio.h>
#include<assert.h>
int mystrcmp(const char *src, const char *dst)
{
assert(src);
assert(dst);
int ret = 0;
while (!(ret = *(unsigned char *)src-*(unsigned char *)dst) && *dst)
{
src++;
dst++;
}
if (ret > 0)
return 1;
else if (ret < 0)
return -1;
return 0;
}
int main()
{
char str[] = "abcde2";
char arr[] = "abcde";
int ret = mystrcmp(str, arr);
printf("%d\n", ret);
system("pause");
return 0;
}