1.strcpy的实现
char * my_strcpy(char * s1, char * s2) { assert(s1 != NULL&&s2 != NULL); char *res = s1; while ((*(res++) = *(s2++))!=‘\0‘); return res; }
2.strlen的实现
int my_strlen(char * s) { assert(s != NULL); int num = 0; while (*(s++)) ++num; return num; }
3.strcmp的实现
int my_strcmp(char * s1, char * s2) { assert(s1 != NULL&&s2 != NULL); while (*s1 == *s2 && ‘\0‘ != *s1 && ‘\0‘ != *s2) { ++s1; ++s2; } if (*s1 == *s2) return 0; else if (*s1 > *s2) return 1; else return -1; }
时间: 2025-01-18 00:30:45