Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Function memcpy in C programming

September 18, 2013 Posted by: GPA Views: 26783 0 comments

Problem

How does memcpy() work? Write simple program using this function.

Solution

In this article, you will know how to use memcpy() function of header file <string.h>.

Declaration:

void *memcpy( void * firstString , const void * secondString, size_t n );

This function copies a specified number of characters from the secondString into the firstString. The function can receive any type of object.

Example:



#include <stdio.h>
#include <stdlib.h>
#include <string.h>//for function memcpy
//main function
int main(int argc, char *argv[])
{
char firstString[50];
char secondString[50]="We copy this string to array firstString";
printf("globalproganswer.com\n");
//call function memcpy and copy string from array of character secondString[] into array firstString[]
memcpy(firstString, secondString, 41);
printf("firstString contains next information: %s",firstString);
printf("\n");//new line
system("PAUSE");//delay
return 0;
}

Output

Function memcpy

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe