您的位置:首页 > 其它

比较字符串大小strcmp

2013-04-29 21:05 344 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: