Write a C99 function named cloneArgv that duplicates an arra
Write a C99 function named cloneArgv that duplicates an array of strings, as received by a C program\'s main function. Your function should have the following prototype: char **cloneArgv(int argc, char *argv[]); where argc is the number of strings in argv. You should assume argc is always strictly greater than zero and that argv contains at least argc elements. You should assume all strings in argv are terminated with a NULL-byte. Your function should make an exact duplicate of the array and its contents, allocating new memory as required.
Solution
Here is the code..
#include <stdio.h>
char ** cloneArgv(int argc, char *argv[]);
int main(int argc, char *argv[]) {
cloneArgv(argc, &argv);
return 0;
}
char ** cloneArgv(int argc, char *argv[])
{
int dup_argc = argc; //new memory allocation
char dup_argv = *argv; //new memory allocation
}
