C Reference String Operation: memcpy()

The function memcpy() copies n characters from source to target.

Usage:

void *memcpy(void *target, void *source, size_t count);

Note: If the copy takes place between objects that overlap, the behaviour is undefined.

memcpy() source code example:


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

	main()
	{
		char line[100];
		char *ptr_my;

		ptr_my=&line[0];
		strcpy(ptr_my, "aaa");

		memcpy(&ptr_my[3], "bbb", 3);
		ptr_my[6]='\0';

		printf("%s\n", ptr_my);
	}

Output of the example:


	aaabbb

This entry was posted in C Reference string.h Functions. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

Comments are closed.