int mystrlen(char * str) {
int i;
for (i = 0; *(str + i) != '\0'; i++) {
//str[i] ************ different
}
return i;
}
void mystrcpy(char * dest, char * src) {
while (*src != '\0')
*dest++ = *src++;
*dest = '\0';//here
}
void mystrcpy1(char * dest, char * src) {//char buf[] = "wepull"; char buf[32] = "wepull";
do {
*dest++ = *src;
} while (*src++ != '\0');
}
void mystrcat(char * dest, char * src) {
while (*dest != '\0')
++dest;
do {
*dest++ = *src;
} while (*src++ != '\0');
}
int mystrcmp(char * s1, char *s2) {
if (s1 == s2) {
return 0;
}
while (*s1 == *s2 && *s1 != '\0' && *s2 != '\0') {
++s1;
++s2;
}
if (*s1 > *s2)
return 1;
else if (*s1 == *s2)
return 0;
else
return -1;
}
char* mystrchr(char* str, char ch) {
char* p = NULL;
int i;
for (i = 0; str[i] != '\0'; ++i) {
if (ch == str[i]) {
p = str + i;
return p;
}
}
}
我以前写的。你看一下吧 差不多
天,你这工作量也忒大了吧