What is the best way to duplicate an integer array? I know memcpy() is one way to do it. Is there any function like strdup()?
memcpy()
strdup()
There isn't, and strdup isn't in the standard, either. You can of course just write your own:
strdup
int * intdup(int const * src, size_t len) { int * p = malloc(len * sizeof(int)); memcpy(p, src, len * sizeof(int)); return p; }