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
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" 11Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started