memcmp.c

来自「传说中的c语言四书五经:一、The C Programming Language」· C语言 代码 · 共 16 行

C
16
字号
#include <string.h>

/*lint -e613
memcmp is defined here because some vendors don't implement
it, strcmp, or strncmp correctly; they must treat the bytes
as unsigned chars.
*/
int memcmp(const void *s1, const void *s2, size_t n) {
	const unsigned char *cs1 = s1, *cs2 = s2;

	for ( ; n-- > 0; cs1++, cs2++)
		if (*cs1 != *cs2)
			return *cs1 - *cs2;
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?