标签:
#include<stdio.h> #include<assert.h> //字符串比较 char my_strcmp(char const *str1,char const *str2) { assert(str1,str2); while (*str1 == *str2) { if (*str1 == '\0') { return 0; } *str1++; *str2++; } if (*str1 > *str2) return 1; else return -1; } int main() { char *p = "abcd"; char *q = "abcdddd"; int ret = my_strcmp(p, q); printf("%d\n",ret); getchar(); return 0; }
#include <stdio.h> #include <assert.h> //字符串复制 void my_strcpy(char *dst, char const *src) { assert(dst); assert(src); while (*src != '\0') { *dst = *src; *dst++; *src++; } *dst = '\0'; } int main() { char p[10] = { 0 }; char *q = "hello"; my_strcpy(p, q); printf("%s\n", p); getchar(); return 0; }
标签:
原文地址:http://blog.csdn.net/lolita0917/article/details/45971617