#include <iostream>
#include <assert.h>
using namespace std;
//比较字符串大小 s - t
int strcmp(const char *s, const char *t)
{
assert(s != NULL && t != NULL); //断言保证传进来的参数不是空
while (*s && *t && *s == *t) //保证两者还有指向内容,并且相等
{
++s;
++t;
}
return (*s - *t);
}
int main(void)
{
char *s = "hello world";
char *t = "hello";
//char a[10] = {0};
cout<<strcmp(s,t);//32
char r = ' ';
cout<<int(r);//空格的值是32
system("pause");
return 0;
}
比较字符串大小strcmp
最新推荐文章于 2024-03-14 13:18:40 发布