Question: Write a program that takes a string of 21 characters and shift the content (left or right) by a given amount. Details You will be

Write a program that takes a string of 21 characters and shift the content (left or right) by a given amount.

Details

You will be given the string properly initialized where the last element (position 20) is going to be the null character '\0'.

You will be given the shift amount as an integer number (positive or negative)

A shift to the left is going to be represented by negative numbers and to the right by positive numbers.

You must only print out the resulting shifted string.

Note: the last character of your string must be always the null character.

Example 1:

When the input is:

Shift: 4, String: How are you, World!? 

The output is

ld!?How are you, Wor 

Example 2:

When the input is:

Shift: -5, String: How are you, World!? 

The output is

re you, World!?How a 

please print in c++ like using printf and scanf, not cout and cin and start off with the following code given:

#include

int main() { int shift; char str[21]; scanf("Shift: %d, String: %20[^ ]s", &shift, str); /* Type your code here. */

return 0; }

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!