Well here is the code, I can only use encode to call rotate_right, I was doing it for any amount of text, then I found I only have to do it for for 1 character that is entered. Changed the code around a bit, now it just ends after it executes the rotate_right function, I tried several ways for it to return control to the encode function, but I'm not entirely sure how to do that.
Code:
#include<stdio.h>
int ch;
int shift;
int encode(int ch, int shift);
int rotate_right(int ch);
int rotate_left(int ch);
int main (int argc, char **argv){
int shift;
int ch;
printf("Enter shift: ");
scanf("%d", &shift);
encode(ch,shift);
return 0;
}
int encode(int ch, int shift){
while(shift > 0){
rotate_right(ch);
shift--;
}
printf("%c", ch);
/*while(shift < 0){
rotate_left(ch);
shift++;
}*/
return 0;
}
int rotate_right(int ch){
ch = getchar();
if((ch >= 65 && ch <= 89) || (ch >= 97 && ch <= 121)){
ch = ch + 1;
}
else if(ch == 122){
ch = ch - 25;
}
else if(ch == 90){
ch = ch - 25;
}
return (0);
}