#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<assert.h> int my_strcmp(const char *dest, const char *src, int len) { assert(dest); assert(src); while (len--) { if (*dest == *src) { dest++; src++; } } if (len == 0) return 0; else return (*dest - '\0') - (*src - '\0'); } int main() { char arr1[] = "abcdeff"; char arr2[] = "abcd"; int len = sizeof(arr1) / sizeof(arr1[0]); int ret = my_strcmp(arr1, arr2, len); printf("%d", ret); system("pause"); return 0; }