Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1088753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:07:01+00:00 2026-05-16T23:07:01+00:00

I fall in some problem. I need to write some function like memcpy(void*, const

  • 0

I fall in some problem.

I need to write some function like memcpy(void*, const void*), which its signature should be:

void arrayCopy(void *dest, int dIndex, const void *src, int sIndex, int len)

I noticed that, in many implementation of memcpy, we cast void* to char*, but I think this is not the case of me, as the arrayCopy function needed to be used on arrays of many types including structs.

So, how can I accomplish this?

EDIT:
the source code might be something like that:

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

void arrayCopy(void *, int, const void *, int, int, size_t);

int main(void)
{
    int i;
    int dest[10] = {1};
    int src [] = {2, 3, 4, 5, 6};

    arrayCopy(dest, 1, src, 0, 5, sizeof(int));

    for (i=0; i<10; i++) printf("%i\n", dest[i]);

    return 0;
}

void arrayCopy(void *dest, int dIndex, const void *src, int sIndex, int len, size_t size)
{
    char *cdest = (char*) dest;
    const char *csrc = (char*) src;
    int i;

    len *= size;

    if (dest == src)
    {
        printf("Same array\n");
    }else
    {
        cdest += (dIndex * size);
        csrc += (sIndex * size);
        for (i=0; i<len; i++)
            *cdest++ = *csrc++;
    }
}

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:07:02+00:00Added an answer on May 16, 2026 at 11:07 pm

    “char * ” is just a bunch bytes, everything in C is ultimately bytes – you can cast a pointer to any data structure to char* (you will also need to know the size in memory of the structure)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've stumbled into a tiny problem, which, for some reason, i have no idea
I need to convert a list of numbers that fall within certain ranges into
I have a seed object which has an instance method seed:fall() which is called
I'm building a application that uses a file to configure some fonts. It's like
I have a problem. I have a client where some of their employees have
Here's a random problem in C black magic I just came up with: Write
I have got some problem implementing bullet physics into my opengl game. The thing
I have some packages that have soft dependencies on other packages with a fall
I have an MVC site which has routes which I need to redirect with
I have a problem which I try to solve with mathematica. I am having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.