Use C memcpy to copy one string to another

Syntax

C memcpy function has the following syntax.

void *memcpy(void *to, const void *from, size_t count);

C memcpy function is from header file string.h.

Description

C memcpy function copies count characters from *from into *to and returns *to.

Example

Use C memcpy function to copy a string.


#include <stdio.h>
#include <string.h>
//from ww  w.  j  av  a  2s.  c  o  m
#define SIZE 80

int main(void)
{
  char buf1[SIZE], buf2[SIZE];

  strcpy(buf1, "When, in the course of...");
  memcpy(buf2, buf1, SIZE);
  printf(buf2);

  return 0;
}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h