MyStrlen
int MyStrlen(char* str) {
int count = 0;
while (*str != '\0') {
str++;
count++;
}
return count;
}
MyStrcat
char* MyStrcat(char* str1, char* str2) {
int len1 = MyStrlen(str1);
int len2 = MyStrlen(str2);
for (int i = 0; i < len2; i++) {
*(str1 + len1 + i) = *(str2 + i);
}
return str1;
}
MyStrcmp
int MyStrcmp(char* str1, char* str2) {
int len1 = MyStrlen(str1);
int len2 = MyStrlen(str2);
int i = 0, j = 0;
int count = 0;
int flag = 0;
while (*(str1+i) != '\0' && *(str2+j) != '\0') {
if (*(str1 + i) == *(str2 + j)) {
count++;
}
else if (*(str1 + i) > *(str2 + j)) {
flag = 1;
break;
}
else {
flag = -1;
break;
}
i++;
j++;
}
if (count == len1 && len1 == len2) {
flag = 0;
}
return flag;
}
MyStrcpy
char* MyStrcpy(char* str1, char* str2) {
int len1 = MyStrlen(str1);
int len2 = MyStrlen(str2);
for (int i = 0; i < len1; i++) {
*(str1+i) = '\0';
}
for (int j = 0; j < len2; j++) {
*(str1+j) = *(str2+j);
}
return str1;
}