Question

Write a C program (.c) that will concatenate two of your favorite phrases. The first phrase...

Write a C program (.c) that will concatenate two of your favorite phrases. The first phrase will be copied in a first string declaration and the second phrase will be copied in a second string declaration. Also provide the total length of the two phrases once you have joined them together.

please include phrases

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here is the complete code in C.

====================================================================

#include <stdio.h>

#include<stdlib.h>

#include <string.h>

int main(){

               

               

                char phrase1[] = "Roses are red.";

                char phrase2[] = "Sky is blue.";

               

                int phrase1Length = strlen(phrase1);

                int phrase2Length = strlen(phrase2);

               

                int totalLength = phrase1Length+phrase2Length;

               

                char* combined_Phrase_Pointer = (char*) malloc(sizeof(char)*(totalLength+1));

               

                strcpy(combined_Phrase_Pointer,phrase1);

                strcat(combined_Phrase_Pointer,phrase2);

               

                combined_Phrase_Pointer[totalLength]='\0';

               

                printf("Combined Phrase \"%s\"\n",combined_Phrase_Pointer);

                printf("Total Length: %d\n",totalLength);

               

}

===================================================================

Add a comment
Know the answer?
Add Answer to:
Write a C program (.c) that will concatenate two of your favorite phrases. The first phrase...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java program that takes the following phrases and encrypts them using a substitution cipher....

    Write a java program that takes the following phrases and encrypts them using a substitution cipher. The program should ask for a key and a phrase and then proceed to encrypt that phrase using the given shared key. Make sure that you have the key for the cipher and the output of encrypted phrases. Encrypt the phrase: He who fights with monsters should look to it that he himself does not become a monster. And if you gaze long into...

  • In C++ write a program that will read three strings from the user, a phrase, a...

    In C++ write a program that will read three strings from the user, a phrase, a letter to replace, and a replacement letter. The program will change the phrase by replacing each occurrence of a letter with a replacement letter. For example, if the phrase is Mississippi and the letter to replace is 's' the new phrase will be "miizzizzippi". in the function, replace the first parameter is a modifiable string, the second parameter is the occurrence of a letter...

  • Write a Python program that takes the following phrases and encrypts them using a substitution cipher....

    Write a Python program that takes the following phrases and encrypts them using a substitution cipher. It should ask for a key and a phrase and then proceed to encrypt that phrase using the given shared key. Make sure that you have the key for the cipher that you use and the output of encrypted phrases. 1. He who fights with monsters should look to it that he himself does not become a monster . And if you gaze long...

  • Two words or phrases in English are anagrams if their letters (and only their letters), rearranged,...

    Two words or phrases in English are anagrams if their letters (and only their letters), rearranged, are the same. We assume that upper and lower case are indistinguishable, and punctuation and spaces don't count. Two phrases are anagrams if they contain exactly the same number of exactly the same letters, e.g., 3 A's, 0 B's, 2 C's, and so forth. Some examples and non-examples of regular anagrams: * The eyes / they see (yes) * moo / mo (no) *...

  • The first issue: write a program in C #, which does the following: 1- Read two...

    The first issue: write a program in C #, which does the following: 1- Read two string strings str1 and str2 entered by the user so that each one is composed from at least five characters. 2- Transferring the first two letters of the str1 to the end of the str2, then writing each of them. 3- Delete the first and last characters of the str2 string, then write the new string that results from Deletion process. 4- Moving two...

  • c programming

    Write a c program that reads a string with a maximum length of 30 from the keyboard[1]. The program should then copy the characters from that input string into a second character array (in order of input). However, only if a character is a vowel (a, e, i, o, u) should it be copied into the second array. Once copied, the program should output the values stored in the second array (in order of input). The program should then count...

  • Write a program that calls the random number generator two times to simulate rolling a pair...

    Write a program that calls the random number generator two times to simulate rolling a pair of dice. It should store the two numbers into variables. It will then determine if the dice roll is a winner (doubles OR add up to 7). Remember to add two includes and also to seed the random number generator to the clock. This will roll two dice and add them together. Doubles, or a total of 7 - YOU ARE A WINNER!!! First...

  • Cipher Program Specifications: You are to write a program called, "Cipher123" that reads in an encoded...

    Cipher Program Specifications: You are to write a program called, "Cipher123" that reads in an encoded message using the 1-2-3 cipher and returns the decoded message. The program should continue prompting for additional encoded messages until the user chooses to quit the program. When decoding a message, we take the first letter of the first word, the second letter of the second word and the third letter of the third word and concatenate them. We repeat this same process 1-2-3...

  • a. Write a program that reads your id and full name and display. And also display...

    a. Write a program that reads your id and full name and display. And also display the index of first letter and last letter of your full name. b. Modify above program, Declare a string course, let your program read course from user, check if course is not equal to comp2002, clear the string otherwise concatenate course and "Computer Science Department". c. Modify above program declare a string college="". If string college is empty then assign a new string "College...

  • Write a program using the PHP application that will create a form for your favorite store....

    Write a program using the PHP application that will create a form for your favorite store. The form should include fields for contact information and at least three(3) items to order from. It should calculate the order and display a subtotal before tax and a total after tax. Also add background color and pictures

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT