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 n );

Since:

BlackBerry 10.0.0

Arguments:

dest
A pointer to where you want the function to copy the data.
src
A pointer to the buffer that you want to copy data from.
c
The value that you want to stop copying at.
n
The maximum number of bytes to copy.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The memccpy() function copies bytes from src to dest, up to and including the first occurrence of the character c (converted into an unsigned char), or until n 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, 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:

POSIX 1003.1 XSI

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

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus