#include <string.h>
int memcmp( const void *buffer1, const void *buffer2, size_t count );
函数比较 buffer1 和 buffer2 的前 count 个字符。返回值如下:
小于0:buffer1 小于 buffer2
等于0:buffer1 等于 buffer2
大于0:buffer1 大于 buffer2
#include <stdio.h>
#include <string.h>
int main() {
char buffer1[] = "This is a String";
char buffer2[] = "This is a string";
printf("result = %d\n", memcmp(buffer1, buffer2, 10));
printf("result = %d\n", memcmp(buffer1, buffer2, 16));
return 0;
}输出结果:
result = 0 result = -1