Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,367 questions

11,628 answers

573 users

How to implement the memcpy() function in C

2 Answers

0 votes
#include <stdio.h>
#include <string.h>
 
void memcpy_implementation(void *dest, void *src, size_t len) {
   char *psrc = (char *)src;
   char *pdest = (char *)dest;
  
   for (int i = 0; i < len; i++)
       pdest[i] = psrc[i];
}
  
int main()
{
    char src[] = "c programming";
    char dest[64];
    memcpy_implementation(dest, src, strlen(src) + 1);
    printf("%s\n", dest);
  
    return 0;
}
 
/*
run:
   
c programming
  
*/

 




answered Jul 6 by avibootz
edited Jul 7 by avibootz
0 votes
#include <stdio.h>
 
void memcpy_implementation(void *dest, void *src, size_t len) {
   char *psrc = (char *)src;
   char *pdest = (char *)dest;
  
   for (int i = 0; i < len; i++)
       pdest[i] = psrc[i];
}
  
int main()
{
    int int_src[] = {13, 65, 99, 150};
    int size = sizeof(int_src)/sizeof(int_src[0]);
    int int_dest[size];
    memcpy_implementation(int_dest, int_src,  sizeof(int_src));
    for (int i = 0; i < size; i++)
        printf("%4d", int_dest[i]);
      
    printf("\n");
     
    return 0;
}
 
/*
run:
   
  13  65  99 150
  
*/

 




answered Jul 6 by avibootz
edited Jul 7 by avibootz
...