strncmp.c
来自「<<c语言接口与实现>>一书源码,此书无疑是一部经典的c」· C语言 代码 · 共 16 行
C
16 行
#include <string.h>
/*lint -e613
strncmp is defined here because some vendors don't implement
it, strcmp, or memcmp correctly; they must treat the bytes
as unsigned chars.
*/
int strncmp(const char *s1, const char *s2, size_t n) {
for ( ; n-- > 0; s1++, s2++)
if (*s1 != *s2)
return (unsigned char)*s1 - (unsigned char)*s2;
else if (*s1 == 0)
return 0;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?