Here's the pertinent info from man string(3):
strcmp() compares its arguments and returns an integer
greater than, equal to, or less than 0, according as s1 is
lexicographically greater than, equal to, or less than s2.
strncmp() makes the same comparison but compares at most n
characters.
Here's the pertinent info from man memory(3):
memcmp() compares its arguments, looking at the first n
characters only, and returns an integer less than, equal to,
or greater than 0, according as s1 is lexicographically less
than, equal to, or greater than s2.
Maybe I'm missing something obvious.
------------------------------------------------------
Ken Bateman bat...@msr.ornl.gov
"We are a hedge. Please move along" -anonymous ninja
No, _you_ didn't miss anything obvious; your man pages did. :-) The key is
that `at most' in the strncmp() text: str* functions take (char)0 (ie ASCII
NUL) to be an end-of-string indicator and stop when they encounter it. The
mem* functions treat NUL as any other character.
so
"I am a string \000 with a hidden tail"
and
"I am a string \000 equiped with a sneaky part"
will compare equal with strncmp, but not with memcmp.
>What's the difference between memcmp() and strncmp()? They take the exact
>same arguments. They appear to behave identically.
strncmp() terminates after n characters OR after hitting a '\0' character,
whichever comes first.
memcmp() does not terminate if it encounters a '\0' character.
--
David F. Skoll
strncmp, stops at the first '\0'