This 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 #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__); }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
icon
Concept explainers
Question

This 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 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__);

}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY