时间:2021-07-01 10:21:17 帮助过:25人阅读
#include <stdio.h> #include <stdlib.h> #include <assert.h> int my_strcmp1(const char *dest,const char *src)//方法1 { assert(dest); assert(src); while (*dest==*src) { if (*dest == ‘\0‘) { return 0; } dest++; src++; } return *dest - *src; } int my_strcmp2(const char *dest, const char *src)//方法2 { int ret = 0; while (!(ret = (*(unsigned char*)dest - *(unsigned char *)src)) && *dest) { dest++; src++; } if (ret > 0) return 1; else if (ret < 0) return -1; else return (ret); } int main() { char arr1[] = "abcd"; char arr2[] = "abcde"; int ret = my_strcmp2(arr1, arr2); printf("%d\n", ret); system("pause"); return 0; }
【C语言】【面试题】【笔试题】模拟实现数据库中strcmp函数
标签:c语言 模拟实现数据库中strcmp函数