Concept explainers
Please fill in the blanks in C.
/* Copy Strings Backward
Input String1: Hello World*/
/* We’ll initialize a string (I’ll use “Hello World”). Then, create a
second string and copy the first string over, but backwards, using a loop. Print both strings.
For example: string 1 is “Hello World”, string 2 would be “dlroW olleH”. */
#include<stdio.h>
#define str_len __1__ //str_len = hello + space + world + null char LEN
__2__ print_string(__3__ str[__4__]);
__5__ copy_string(__6__ s1[__7__], __8__ s2[__9__]);
int main()
{
__10__ str1[]= "Hello World";
__11__ str2[__12__];
//loop and copy each character over
// until the array reaches null character
copy_string(__13__, __14__);
//printing back by calling function print_string
printf("String1: ");
print_string(__15__);
printf("\nString2: ");
print_string(__16__);
}
/*Copy one string to another by looping backward.
Need 2 index variables to keep track of each string.
For ex: string1 = "hello", len = 6 (1 for null character)
string2[0] = string1[4] // letter 'o'
string2[1] = string2[3] // letter 'l'
Notice the index value compare to the len.*/
__17__ copy_string(__18__ s1[__19__], __20__ s2[__21__])
{
int idx1, idx2 = 0; //this is the index counter for the 2 strings s1 and s2
/*be careful here. We'll loop from the end of str1 to get letter 'd'
normally, for array, last character is size-1, but for string,
the last index is the null character, not the last character*/
for(idx1= str_len - __22__; idx1 >= __23__ ; idx1 __24__)
{
/*Copy each char from string s1 to string s2*/
__25__[__26__] = __27__[__28__];
/*idx1 for s1 is updated with for loop
update idx2 to save in the next location of s2.*/
idx2++;
}
//After reading all characters,need to add something in the last
//index position to let the program knows the string has ended.
s2[__29__] = '__30__';
}
/*
Printing all letter until the null character is reached.
printf("%s", str) would work, but we are doing this way
to make sure we understand how string works.
Loop through all character until it reaches null character*/
__31__ print_string(__32__ str[str_len])
{
for(int i = 0; str[i] != __33__; i++)
printf("%c", __34__);
}
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 6 images
Where is the solution? You just copy paste my question. Would you please check the solution?
Where is the solution? You just copy paste my question. Would you please check the solution?
- USing basic C++ code pls!!!arrow_forwardMad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways. Write a program that takes a string and an integer as input, and outputs a sentence using the input values as shown in the example below. The program repeats until the input string is quit and disregards the integer input that follows. Ex: If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps the doctor away. Eating 2 shoes a day keeps the doctor away.arrow_forwardPrograming Carrow_forward
- Please help me solve this problem C. Chess Boundary Positions: Write a program called chess_pos.py On a chessboard, positions are marked with letters between a and h for the column and a number between 1 and 8 for the row. Give a 2 character input string with a letter (a-h) and a number (1-8), print "Corner" if the value indicates a square on a corner. Print "Border" if the value indicates a square on an edge of the board. Otherwise, print "Inside".arrow_forwardThis is C programming. Please fill in the blank. Code is to copy string and print backward. /* Requirement: We’ll initialize a string (I’ll use “Hello World”). Then, create a second string and copy the first string over, but backwards, using a loop. Print both strings. For example: string 1 is “Hello World”, string 2 would be “dlroW olleH”. */ /*Copy Strings Backward Input String1: Hello World*/ #include<stdio.h> #define str_len __1__ //str_len = hello + space + world + null char LEN __2__ print_string(__3__ str[__4__]); __5__ copy_string(__6__ s1[__7__], __8__ s2[__9__]); int main() { __10__ str1[]= "Hello World"; __11__ str2[__12__]; //loop and copy each character over // until the array reaches null character copy_string(__13__, __14__); //printing back by calling function print_string printf("String1: "); print_string(__15__); printf("\nString2: "); print_string(__16__); } /* Copy one string to another by looping backward. Need 2 index variables to keep track of each…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY