一种字符串比较函数实现,我有个地方没看懂,请广大网友指点一二:
int strncmp
(
const char * s1, /* string to compare */
const char * s2, /* string to compare to */
size_t n /* max no. of characters to compare */
)
{
if (n == 0)
return (0);
while (*s1++ == *s2++)
{
if ((s1 [-1] == EOS) || (--n == 0))
return (0);
}
return ((s1 [-1]) - (s2 [-1]));
}
s【-1】可以代表s【0】吗?
为什么用s【-1】比用s【0】好呢?
阅读(1452) | 评论(0) | 转发(0) |