In this section write a macro to transfer a block of memory

In this section, write a macro to transfer a block of memory of size N from a source location to a destination using a MACRO called memorycopy. This MACRO has three parameters: SOURCE, DESTINATION, and SIZE. Then, write a program that transfers N bytes from 10 different sources, whose sizes are N bytes. to 10 different destinations with the same size using the written macro, that is. memorycopy.

Solution

#include <stdio.h>
#include <string.h>
#define memorycopy(ms1, ms2, n) memcpy(ms1, ms2, n); //Macro
int main()
{
char so[10][50], de[10][50];
int r, c = 0;
printf(\"\ Enter 10 Source data: \");
for(r = 0; r < 10; r++)
{
fflush(stdin);
gets(so[r]);
}

for(r = 0; r < 10; r++)
{
printf(\"\ \ Enter number of character to copy: \");
scanf(\"%d\", &c);

//Macro call
memorycopy(de[r], so[r], c);

printf(\"\ \ Original message: \");
fflush(stdout);
puts(so[r]);
fflush(stdout);
printf(\"After memorycopy(): \");
puts(de[r]);
}
}

 In this section, write a macro to transfer a block of memory of size N from a source location to a destination using a MACRO called memorycopy. This MACRO has

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site