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: 3938048 • 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

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
}

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