#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int Mystrcmp(char* str1, char* str2) {
assert(*str1);
assert(*str2);
while (*str1 != '\0') {
if (*str1 > *str2) {
return 1;
}
else if (*str1 < *str2) {
return -1;
}
else {
++str1;
++str2;
}
}
if (*str2 != '\0') {
return -1;
}
else {
return 0;
}
}
int main() {
char str1[] = "abcdef";
char str2[] = "abcdef";
int result = Mystrcmp(str1, str2);
printf("%d\n", result);
system("pause");
return 0;
}
C语言实现strcmp
最新推荐文章于 2022-11-24 20:26:40 发布