#include <iostream>
using namespace std;
//compare two string
int strcmp(char * p1, char* p2) {
while (p1 != '\0' && p2 != '\0' && *p1 == *p2 )
{
++p1;
++p2;
}
if (*p1 == '\0' && *p2 == '\0')
{
return 0;
}
if (*p1 == '\0')
{
return -1;
}
if (*p2 == '\0')
{
return 1;
}
return *p1 - *p2;
}
int main(void){
char a1[] = "hello";
char a2[] = "hi";
char a3[] = "he";
cout<<strlen(a1);
cout<<strlen(a2);
int diff = strcmp(a1, a2);
cout<<diff<<endl;
diff = strcmp(a1, a3);
cout<<diff<<endl;
system("pause");
return 0;
}
compare two string
最新推荐文章于 2023-06-27 16:33:30 发布