### memccpy -- Copy Bytes

Format

>     #include <string.h>     /* also in <memory.h> */
>     void *memccpy(void *dest, void *src, int c, unsigned cnt);

Language Level: Extension
memccpy copies bytes from src to dest, up to and including the first occurrence of the character c or until cnt bytes have been copied, whichever comes first.

Return Value
If the character c is copied, memccpy returns a pointer to the byte in dest that immediately follows the character. If c is not copied, memccpy returns NULL.

Example
This example copies up to 55 characters, or until it copies the '.' character, from the source to the buffer.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    char source[60];
    char result[60];

    int main(void)
    {
       memcpy(source, "This is the string. This part won't be copied.", 55);
       if (NULL == memccpy(result, source, '.', 55)) {
          printf("Error in copying source.\n");
          exit(EXIT_FAILURE);
       }
       else
          printf("%s\n", result);
       return 0;

       /*******************************************************************
          The output should be:

          This is the string.
       *******************************************************************/
    }

memchr -- Search Buffer
memcmp -- Compare Buffers
memcpy -- Copy Bytes
memmove -- Copy Bytes
memset -- Set Bytes to Value
<memory.h>
<string.h>