Question: Write a C++ function named stringCopy that takes two C-strings s1 and s2 and copies the characters of s1 to s2. Note that when we

Write a C++ function named stringCopy that takes two C-strings s1 and s2 and copies the characters of s1 to s2. Note that when we call this function from the main program, both S1 and S2 are created such that the null character is placed at the end of both of them. For this reason, inside this function it is easy to compute the length of S1 and S2 using stringLength function given in question #1 to find lengths. The copying of characters of S1 to S2 must follow the following rules: Rule 1: If the length of S1 and S2 are equal, then copy all the characters of S1 to S2. Rule 2: If the length of S2 is smaller than length of S1 then S2 does not have enough space to copy all the characters of S1. Therefore this function should NOT copy any character of S1 to S2 and must return without doing anything. Rule 3: If the length of S2 is greater than length of S1 then copy all the characters of S1 to S2 and put a null character next to the last character copied. Therefore in this case S2 will have two null characters: one at the end of it which was put in the main program and another next to the last character copied which is put in this function. The main program to test the stringCopy function is given below

 Write a C++ function named stringCopy that takes two C-strings s1

and s2 and copies the characters of s1 to s2. Note that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!