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
How to reset windows 7 password without logging in
hammer [34]

Explanation:

<em>.</em><em>Reboot your laptop or PC. </em>

<em>Select the Repair your Computer option and press Enter. </em>

<em>The System Recovery Options window will popup, click System Restore, it will check the data in your Restore Partition and factory reset laptop without password.</em>

4 0
3 years ago
Read 2 more answers
Jack lost all the data he saved on his desktop because of a power outage while working on a presentation on which of these compu
Alchen [17]
The hard drive should have saved his data.
5 0
3 years ago
Read 2 more answers
Given the structure definition shown, assume that circle1 and circle2 are variables of the Circle type and their members have be
kolezko [41]

Answer:

False is the correct answer for the above question.

Explanation:

  • The structure is a user-defined data type, which is used to define the set of different data types and values. Just like in the above question, the class structure holds the list of three variables, which is a type of double.
  • When any user wants to compare the two structure values, then he can do it with the help of comparing all the variables of a structure. if a user wants to compare the circle1 with the value of the circle2, then he needs to compare the circle1.centerX with circle2.centerX, and so on with the other variables.
  • But the above question syntax will directly compare the two structure variable, which is not correct. Hence the above answer is false.
6 0
4 years ago
) The _____ method of a radio button returns true if that button is on.
Lostsunrise [7]

Answer:

isSelected()

Explanation:

The isSelected() method of a radio button returns true if that button is on and false otherwise. This method is defined in the class javax.swing.AbstractButton. JRadioButton class inherits from AbstractButton and thus has access to this method. An application code can invoke this method on the radio button instance to determine th ecurrent state and alter the control flow accordingly.

4 0
3 years ago
12. In 2009, __________ of all pedestrian fatalities were caused by impaired drivers
makvit [3.9K]
3% of pedestrian fatalities were caused by impaired drivers  
4 0
3 years ago
Read 2 more answers
Other questions:
  • The key invention that enabled computers to go into every home and office is
    7·1 answer
  • It's inventiveness uncertainty and futuristic ideas typically deals with science and technology ......what is it.
    8·1 answer
  • What command would Emile use in his word processing software to insert a bar chart that will automatically adjust to changes mad
    6·2 answers
  • Many interesting science-, technology-, engineering-, and math-oriented websites provide open-source data to the public. Which o
    8·1 answer
  • What size segment will be allocated for a 39 KB request on a system using the Buddy system for kernel memory allocation?A) 42 KB
    11·1 answer
  • Use the drop-down menu to correctly identify the numbering system.
    7·1 answer
  • Characteristics of 1st generation​ computers
    5·1 answer
  • A third party that provides a computer system such as Windows, programming applications, databases, and web servers is demonstra
    6·1 answer
  • Write pseudo code that performs the following: Ask a user to enter a number. If the
    13·1 answer
  • What are backup storage device of computer ?​
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!