#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
int Strcmp(const char* str1, const char* str2)
{
assert(str1 != NULL && str2 != NULL);
while (*str1 != ‘\0’ && *str2 != ‘\0’)
{
if (*str1 > * str2)
return 1;
else if (*str1 < *str2)
return -1;
str1++;
str2++;
}
if (*str1 == ‘\0’ && *str2 == ‘\0’)
{
return 0;
}
if (*str1 == ‘\0’)
return -1;
return 1;
}
int main()
{
char str1[] = “heheheheheheheh”;
char str2[] = “heheheheheheheh”;
int judge = Strcmp(str1, str2);
if (judge > 0)
printf(“str1>str2\n”);
else if (judge < 0)
printf(“str1<str2\n”);
else
printf(“str1==str2\n”);
system(“pause”);
return 0;
}
strcmp
最新推荐文章于 2024-11-14 23:00:39 发布
384

被折叠的 条评论
为什么被折叠?



