Question

In: Computer Science

Can you add code to this so that it finishes the combine function. Given two words...

Can you add code to this so that it finishes the combine function. Given two words as input, the output of the program should be the two words combined together with a space between them. Not allowed to use any external libraries for this assignment.

#include <stdio.h>
#include <stdlib.h>
void combine(char* p, char* q){
/* Add the necesary logic here to combine the strings
in the dynamic array p and q by inserting a space
between two words
and write the result back to p */

  
}
int main(){
/* No changes should be done in this part */
char* word1 = malloc(sizeof(char) * 128);
char* word2 = malloc(sizeof(char) * 128);
printf("Enter your first word:\t");
scanf("%s", word1);
printf("Enter your second word:\t");
scanf("%s", word2);
combine(word1, word2);
printf("%s\n", word1);

  

}

Solutions

Expert Solution

Program :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void combine(char* p, char* q)
{

int l1;
int l2;
int i;
l1=strlen(p);
l2=strlen(q);
p[l1]=' ';
while(i<l2)
{
p[l1+1]=q[i];
l1=l1+1;
i=i+1;
}
}
int main()
{
/* No changes should be done in this part */
char* word1 = malloc(sizeof(char) * 128);
char* word2 = malloc(sizeof(char) * 128);
printf("Enter your first word:\t");
scanf("%s", word1);
printf("Enter your second word:\t");
scanf("%s", word2);
combine(word1, word2);
printf("%s\n", word1);
return 0;
}

Screenshot of the program:

Output of program :


Related Solutions

2. Specification - Given the following code base, add the appropriate function that will give the...
2. Specification - Given the following code base, add the appropriate function that will give the correct results/output. CODE: # TODO : Add Two Missing Functions HERE mlist = [(" Orange ", 10 , 0.25) ,( " Apple ", 5 , .20) , (" Banana ", 2 , 0.3) ,(" Kiwi ", 1 , 0.5)] addFruit (10 ," Lemon " ,0.1) displayFruitList ( mlist ) OUTPUT: Orange --- $ 2.50 Apple --- $ 1.00 Banana --- $ 0.60 Kiwi ---...
code in c++ using the code given add a hexadecimal to binary converter and add a...
code in c++ using the code given add a hexadecimal to binary converter and add a binary to hexadecimal converter #include <iostream> #include <string> #include<cmath> #include<string> using namespace std; int main() { string again; do { int userChoice; cout << "Press 2 for Decimal to Binary"<< endl; cout << "Press 1 for Binary to Decimal: "; cin >> userChoice; if (userChoice == 1) { long n; cout << "enter binary number" << endl; cin>>n; int decnum=0, i=0, remainder; while(n!=0) {...
Change the format of the given code to two columns, add a sub title and an...
Change the format of the given code to two columns, add a sub title and an author name and increase the color and thickness of the column-rule. Add an image and float the text around the image. <!DOCTYPE html> <!-- Fig. 5.17: multicolumns.html --> <!-- Multicolumn text in CSS3. --> <html> <head> <meta charset = "utf-8"› <title>Multicolumns</title> <style type = "text/css"› p { margin:0.9em Oem; } .multicolumns { /* setting the number of columns to 3 */ -webkit-column-count: 3; -moz-column-count:...
Can you add more comments explaining what this code does? i commented what I know so...
Can you add more comments explaining what this code does? i commented what I know so far #include<stdio.h> #include<pthread.h> #include<semaphore.h> #include<unistd.h> sem_t mutex,writeblock; int data = 0,rcount = 0; int sleepLength = 2; // used to represent work void *reader(void *arg) { int f; f = ((int)arg); sem_wait(&mutex); // decrement by 1 if rcount = rcount + 1; if(rcount==1) sem_wait(&writeblock); sem_post(&mutex); printf("Data read by the reader%d is %d\n",f,data); //shows current reader and data sleep(sleepLength); // 1 second of "work" is...
Add two lines of code in main() function to create a variable, goodStudent, whose type is...
Add two lines of code in main() function to create a variable, goodStudent, whose type is Student with name, "John" and age, 21. public class Student { private String name; private int age; public Student(){ name = ""; age= 0; } public Student(String initName){ name = initName; age = 0; } public String getName() { return name; } public void setAge(int anAge) { age = anAge; } public static void main (String[] args) { // !!!! Your two lines of...
Given the following HTML code (You are not allowed to add additional id or class to...
Given the following HTML code (You are not allowed to add additional id or class to the file test.html) test.html <h1>Down the Rabbit-Hole</h1> <div class="bb" >        <p class="bb" >Alice was beginning to get very tired ...</p>    <br/>    <p> Alice </p> </div> <div id="aa">    <p>Down, down, down. Would the fall never come to an end</p>    <div> <p class="bb" >I wonder if I shall fall right …</p> </div> </div> <h1> Upcoming Event </h1> <p> Excitng Event: 101 </p> <p> A limited number...
Modify the original code and add an additional function of your choice. The function should be...
Modify the original code and add an additional function of your choice. The function should be unique and something you created for this assignment. Support your experimentation with screen captures of executing the new code. Prepare a test table with at least 3 distinct test cases listing input and expected output for your unique function. #include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x) = x*x*x\n"); printf ("c: c(x) = x^2 + 2*x...
Can you please take this code and just rewrite it so it can be easily be...
Can you please take this code and just rewrite it so it can be easily be able to put into a complier. in java Implementation of above program in java: import java.util.HashMap; import java.util.Scanner; import java.util.Map.Entry; public class Shopping_cart {       static Scanner s= new Scanner (System.in);    //   declare hashmap in which key is dates as per mentioned and Values class as value which consists all the record of cases    static HashMap<String,Item> map= new HashMap<>();    public...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
QUESTION: Add code so that if no parameter values are specified for method “main”, then the...
QUESTION: Add code so that if no parameter values are specified for method “main”, then the error message “file name expected” is printed out instead of the "Opening file " message. Hint: If no parameter values are specified for method “main”, then the length of the array “args” will be zero. If that error message “file name expected” is printed out, the program should stop. You can make any Java program stop using this line … System.exit(0); skeleton code: /**...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT