Hi this is my code below, now whats confusing me much is the while(scanf) part
i havent completed the function i am trying to implore, but what this program is supposed to do is descrypt or encrypt very simply some letters
what problem i am having is this, when the while runs the function scanf("%c",encode(ch)))
it is supposed to take all the letters that is input and do with them accordingly, the shift integer determines if they will be scrambled down or up, so if shift is less than 0 it will take the letter and according to what shift is set to it will replaces that may times down from the original letter with this letter n times away governed by the shift variable
now again the problem i am having is with the encode ch function i wrote, i dont know what scanf is supposed to do with it, does it return negative when what happens? when is it supposed to end?
Code:
#include <stdio.h>
int rotate_right(int);
int rotate_left(int);
int encode( int, int);
int main(void)
{
int ch=0,shift,n;
printf("Enter a number for amount of rotation: ");
scanf("%d",&shift);
while(scanf("%c",encode(ch, shift)))
printf("%c",ch);
return 0;
}
int encode(int ch, int shift){
while(shift!=0){
if(shift>0){
rotate_right(ch);
shift-=1;
}
else if(shift<0){
rotate_left(ch);
shift+=1;
}
}
return ch;
}
int rotate_right(int ch){
if((ch >= 'A'&& ch < 'Z')||(ch >= 'a'&& ch < 'z'))
ch++;
else if(ch == 'Z')
ch = 'A';
else if(ch == 'z')
ch = 'a';
return ch;
}
int rotate_left(int ch){
if((ch > 'A'&& ch <= 'Z')||(ch > 'a'&& ch <= 'z'))
ch--;
else if(ch == 'A')
ch = 'Z';
else if(ch == 'a')
ch = 'z';
return ch;
}