Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C99 function named cloneArgv that duplicates an array of strings, as rec

ID: 3939263 • Letter: W

Question

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.

Explanation / Answer

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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote