Memory Block Management
The following functions declared in string.h are used to compare, search, or initialize memory buffers:
-
void *
memchr
( const void *buf
, intc
, size_tn
); Searches the first
n
bytes of the bufferbuf
for the first occurrence of the characterc
.-
void *
memcmp
( const void *s1
, const void *s2
, size_tn
); Compares the first
n
bytes in the buffers1
with the corresponding bytes in the buffers2
. The return value is less than, equal to, or greater than0
to indicate whethers1
is less than, equal to, or greater thans2
.-
void *
memcpy
( void *dest
, const void *src
, size_tn
); Copies
n
bytes from the buffersrc
to the bufferdest
.-
void *
memmove
( void *dest
, const void *src
, size_tn
); Copies
n
bytes from the buffersrc
to the bufferdest
. In case the buffers overlap, every character is read before another character is written to the same location.-
void *
memset
( void *dest
, intc
, size_tn
); Fills the first
n
bytes of the bufferdest
with the characterc
.
The corresponding wmem...
functions, for handling
buffers of wide characters with type wchar_t
, are
declared in the header file
wchar.h
(*).
Get C Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.