int strcmp(const char *s1, const char *s2)
{
int ret = 0;
while (!(ret = *(unsigned char *) s1 - *(unsigned char *) s2) && *s2) ++s1, ++s2;
if (ret < 0)
ret = -1;
else if (ret > 0)
ret = 1 ;
return ret;
}
Run Code Online (Sandbox Code Playgroud)
我查看了以下代码:http://www.jbox.dk/sanos/source/lib/string.c.html
我想有一些问题.如果strlen(s2)>strlen(s1),则++s1可能超出范围.不幸的是,然后函数返回错误.
| 归档时间: |
|
| 查看次数: |
16580 次 |
| 最近记录: |