[Previous] [Contents] [Next]

memccpy()

Copy bytes between buffers until a given byte is found

Synopsis:

#include <string.h>

void* memccpy( void* dest, 
               const void* src,
               int c,
               size_t cnt );

Library:

libc

Description:

The memccpy() function 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.

Returns:

A pointer to the byte in dest following the character c, if one is found and copied; otherwise, memccpy() returns NULL.

Examples:

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

char* msg = "This is the string: not copied";

int main( void )
{
    char buffer[80];

    memset( buffer, '\0', 80 );
    memccpy( buffer, msg, ':', 80 );

    printf( "%s\n", buffer );
    
    return EXIT_SUCCESS;
}

produces the output:

This is the string:

Classification:

Standard Unix

Safety:
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

memchr(), memcmp(), memcpy(), memicmp(), memmove(), memset()


[Previous] [Contents] [Next]