int memcmp(const void *str1, const void *str2, size_t n)
if Return value < 0 then it indicates str1 is less than str2.
if Return value > 0 then it indicates str2 is less than str1.
if Return value = 0 then it indicates str1 is equal to str2.
上網只查到它的回傳值是大於、等於或小於0的整數,但是都沒有一個實際的值,想請問一下這個function真的沒有一個固定的retrun value嗎?
// g++ cpp-memcmp.cpp -o a.out
#include <stdio.h>
#include <string.h>
int main() {
char buffer1[] = "abcde";
char buffer2[] = "abcde";
int ret = memcmp(buffer1, buffer2, sizeof(buffer1));
if (ret > 0) {
printf("buffer1 is greater than buffer2\n");
printf("%d", ret);
} else if (ret < 0) {
printf("buffer1 is less than buffer2\n");
printf("%d", ret);
} else { // ret == 0
printf("buffer1 is equal to buffer2\n");
printf("%d", ret);
}
return 0;
}
自己列印出來不就知道了!