We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.


Copies characters from a buffer.

void *_memccpy(
   void *dest,
   const void *src,
   int c,
   size_t count 


Pointer to the destination.


Pointer to the source.


Last character to copy.


Number of characters.

If the character c is copied, _memccpy returns a pointer to the char in dest that immediately follows the character. If c is not copied, it returns NULL.

The _memccpy function copies 0 or more characters of src to dest, halting when the character c has been copied or when count characters have been copied, whichever comes first.

Security Note   Make sure that the destination buffer is the same size or larger than the source buffer. For more information, see Avoiding Buffer Overruns.


Required header


<memory.h> or <string.h>

For more compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.

// crt_memccpy.c

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

char string1[60] = "The quick brown dog jumps over the lazy fox";

int main( void )
   char buffer[61];
   char *pdest;

   printf( "Function: _memccpy 60 characters or to character 's'\n" );
   printf( "Source: %s\n", string1 );
   pdest = _memccpy( buffer, string1, 's', 60 );
   *pdest = '\0';
   printf( "Result: %s\n", buffer );
   printf( "Length: %d characters\n", strlen( buffer ) );

Function: _memccpy 60 characters or to character 's'
Source: The quick brown dog jumps over the lazy fox
Result: The quick brown dog jumps
Length: 25 characters