1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
IgorC [24]
3 years ago
10

Complete the following function to create a deep-copy on the heap of the argv array. Set the result pointer to point to your arr

ay. The only library calls you may use are malloc and memcpy. You may not use strdup.
Computers and Technology
1 answer:
irga5000 [103]3 years ago
8 0

Answer:

Following are the code in the C programming Language.

//define function

void duplicate(char*argv, char**result) {

//set and initialize the variable to 0

int c = 0;

//set and initialize the char type pointer variable

char** t = argv;

//set the while loop

while(t){

//increment by 1

c++;

//increment by 1

t++;

}

//set malloc function in the pointer variable

result= malloc(sizeof(char)*(c+1));

//set the for loop

for(int i = 0; i < c; i++) {

//set malloc function in the pointer

(*result)[i] = malloc(strlen(argv[i])+1);

//copy the character from memory

memcpy(argv[i], (*result)[i], strlen(argv[i])+1) ;

}

//initialize null in the pointer

(*result)[i] = NULL;

}

Explanation:

In the following code, we define function "duplicate()" and pass two character type pointer arguments "*argv" and "**result" and inside the function.

  • Set an integer type variable "c" and initialize to 0.
  • Set character type pointer variable "t" and initialize the value of pointer variable "argv".
  • Set the while loop and increment in the variable "c" and "t" by 1.
  • Set the malloc function in the pointer variable "result".
  • Set the for loop to copy the character from the memory.
  • Finally, initialize the pointer variable "result" to NULL.
You might be interested in
The BCD number for decimal 473 is( ). a) 111011010; b) 010011110011; c) 010001110011; d)0010110110​
jek_recluse [69]

Answer:

001101000111 is the bcd no for 347

8 0
3 years ago
3. Under the Driver Responsibility Program, you may be assigned a number of points for:
slava [35]

Hello ur answer should be A

8 0
3 years ago
Read 2 more answers
Which collaboration website is best suited for social collaboration? www.media.iearn.org/projects www.meetup.com www.quest.nasa.
olga55 [171]
The first option is the correct answer
6 0
3 years ago
Your worksheet has the value 27 in cell B3. What value is<br>returned by the function =MOD(B3,6)?​
Digiron [165]

Answer:

3

Explanation:

MOD means the remainder after a division calculation.

\frac{27}{6}= 4r3

The remainder is 3

5 0
3 years ago
8.10 Code Practice Question 3
Alchen [17]

terms = ["Bandwidth", "Hierarchy", "IPv6", "Software", "Firewall", "Cybersecurity", "Lists", "Program", "Logic",

        "Reliability"]

def swap(arr, in1, in2):

   w = arr[in1]

   arr[in1] = arr[in2]

   arr[in2] = w

print(terms)

swap(terms, 5, 1)

swap(terms, 2, 4)

swap(terms, 3, 5)

swap(terms, 5, 6)

swap(terms, 6, 8)

swap(terms, 8, 9)

print(terms)

This is how I interpreted the question. If I need to make any changes, I'll do my best. Hope this helps though.

4 0
3 years ago
Other questions:
  • If num is an int which expression always evaluates to true if num holds an odd number
    14·1 answer
  • Your traffic light changes to yellow as you approach an intersection. In most cases, what action should you take?
    15·2 answers
  • Emotional intelligence is a new term to describe personal traits ?
    12·1 answer
  • Which of the following is not part of active listening?
    6·2 answers
  • Using underlining and italics at the same time is which of these? A. allowed but might be overkill B. always a good idea C. not
    15·2 answers
  • Assume that a 5 element array of type string named boroughs has been declared and initialized. Write the code necessary to switc
    5·1 answer
  • (d) What other services beside cloud-based software may be provided by Internet hosts?[1]
    11·1 answer
  • [1] Our son has started playing organized T-ball, a beginner’s version of baseball. [2] “Organized” is what parents call it, any
    9·2 answers
  • With a(n) ______, a search engine will show ads that have the keyword typed exactly as the searcher used, but may also have othe
    6·1 answer
  • Between the div tags below, type the code for a link to the second.html page. Use "Go to the Second Page" as the link text
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!