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
You can do like this.
#include<stdio.h>
#include<conio.h>
int clone_argc;
char **clone_argv;
void print_args()
{
int a;
for(a=1;a<clone_argc;a++)
{
puts(clone_argv[a]);
}
}
int main(int argc,char **argv)
{
clone_argc=argc;
clone_argv=argv;
print_args();
return 0;
}
