codescracker


c

C memcpy()



« Previous Chapter Next Function »


memcpy()

The memcpy() function copies count characters from the array pointed to by from into the array pointed to by to. If arrays overlap, the behaviour of memcpy() is undefined.

The memcpy() function returns a pointer to to.

memcpy() Syntax

Following is the syntax of the memcpy() function :

#include<string.h>
void *memcpy(void *to, const void *from, size_t count);

memcpy() Example

Following program copies the contents of buf1 into buf2 and displays the result :

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

#define SIZE 80

void main()
{
	clrscr();
	char buf1[SIZE], buf2[SIZE];
	strcpy(buf1, "When, in the course of...");
	memcpy(buf2, buf1, SIZE);
	printf(buf2);
	getch();
}

« Previous Chapter Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test