- void *memchr (void *s, int c, size_t n) -- This memory funtion Search for a character in a buffer .
- int memcmp (void *s1, void *s2, size_t n) -- this function Compare two buffers.
- void *memcpy (void *dest, void *src, size_t n) -- this function Copy one buffer into another .
- void *memmove (void *dest, void *src, size_t n) -- Move a number of bytes from one buffer lo another.
- void *memset (void *s, int c, size_t n) -- Set all bytes of a buffer to a given character.
Their use is fairly straightforward and not dissimilar to comparable string operations (except the exact length (n) of the operations must be specified as there is no natural termination here).
Note that in all case to bytes of memory are copied. - The sizeof() function comes in handy again here, for example:
char src[SIZE],dest[SIZE];int isrc[SIZE],idest[SIZE];
memcpy(dest,src, SIZE); /* Copy chars (bytes) ok */
memcpy(idest,isrc, SIZE*sizeof(int)); /* Copy arrays of ints */
memmove() behaves in exactly the same way as memcpy() except that the source and destination locations may overlap. - memcmp() is similar to strcmp() except here unsigned bytes are compared and returns less than zero if s1 is less than s2 etc.
No comments:
Post a Comment