#include <iostream>
#include <assert.h>
using namespace std;
int strcmp_mf(const char *src,const char *dst)
{
assert(src != NULL && dst != NULL);
while(*src++ == *dst++)
{
if(*src=='\0' && *dst=='\0')
{
return 1;
//比较结果为两个字符串相同
}
}
return 0;//不同
}
void main()
{
const char *s1="lmf" ;
const char *s2="bxy";
if(strcmp_mf(s1,s2))
{
cout << "They are lovers" <<endl;
}
else
{
cout << "They are married" <<endl;
}
}
【面试题】strcmp函数实现
最新推荐文章于 2021-12-22 14:29:07 发布