Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language: C Implement a function void *rotate string in place(char *str, unsigned int disp) that accepts a string and a displacement and rotates each alphabetical

Language: C

image text in transcribed

Implement a function void *rotate string in place(char *str, unsigned int disp) that accepts a string and a displacement and rotates each alphabetical character in the string by the given displacement to the right where 0 disp 2600. Non alphabetical characters are retained without modification. Right shifting a char- acter beyond Z by 1 rotates around to A (similarly z rotates around to a). The input string is modified by the function.

Sample input and output (see picture)

My code:

void rotate_in_place(char *str, unsigned int disp){

if(disp 2600){

char *error = (char *)malloc(strlen("ERROR: disp must be 0

strcpy(error, "ERROR: disp must be 0

printf("%s ", error);

}

int i;

for(i = 0; str[i] != '\0'; i++){

if(is_alpha(str[i])){

if((str[i] + (char)disp) > 90 && (str[i] + (char)disp)

str[i] = str[i] + (char)disp;

str[i] = str[i] - 26;

}

else{

str[i] = str[i] + (char)disp;

}

}

}

str[i] = '\0';

printf("WE ROTATE: %s ", str);

}

My output:

"Hello World" -> "Mjqqt Btwqi"

"gcc -c hw.c -o hw" -> "??? -? ??.? -? ??" X

str "Hello World" displacement str after calling rotate string_in_place "Mjqqt Btwqi" 100 "Spj Jzf!" 2413 "bxx -x cr.x -j cr" 0 "Hello" 26 "Hello" "Hey You!" "gcc -c hw.c -o hw" "Hello" "Hello" 11

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logistics Lifeline Supply Chain Strategies

Authors: Ehsan Sheroy

1st Edition

7419377502, 978-7419377503

More Books

Students also viewed these Databases questions