On 29.11.2010 05:29, Ming Lei wrote:
#include <stdio.h>
#include <errno.h>
int main() {
char *STR = "XXXX\0";
char *XXX = "XXXX";
int a, b;
errno = 0; a = memcmp(STR, XXX, 5); a += errno;
errno = 0; b = strncmp(STR, XXX, 5); b += errno;
printf("5 chars: %d %d \n", a, b);
errno = 0; a = memcmp(STR, XXX, 4); a += errno;
errno = 0; b = strncmp(STR, XXX, 4); b += errno;
printf("4 chars: %d %d \n", a, b);
printf("SWAP STRINGS\n");
errno = 0; a = memcmp(XXX, STR, 5); a += errno;
errno = 0; b = strncmp(XXX, STR, 5); b += errno;
printf("5 chars: %d %d \n", a, b);
errno = 0; a = memcmp(XXX, STR, 4); a += errno;
errno = 0; b = strncmp(XXX, STR, 4); b += errno;
printf("4 chars: %d %d \n", a, b);
return 0;
}
----
# ./a.out
5 chars: 0 0
4 chars: 0 0
SWAP STRINGS
5 chars: 0 0
4 chars: 0 0
But I think the same thing ;)
--
Pavel.
--