Question: 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

Language: C Implement a function void *rotate string in place(char *str, unsigned

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

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!