C Reference String Operation: memmove()

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

Usage:

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

Note: The copy still works if the objects overlap.

memmove() source code example:


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

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

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

		memmove(&ptr_my[3], "bbb", 2);

		ptr_my[5]='\0';
		printf("%s\n", ptr_my);
	}

Note: we give three b’s, but the count is set to 2. Make the ‘\0′ is put at the right position.

Output of the example:


	aaabb

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.