Basically this function is supposed to accept a user inputted string, and the amount it is supposed to be transposed by 'x' amount (between 0-25).
The idea behind transposition is that if the user enters "abc" for the string and then wants to transpose it by 1. The new string is "bcd" changing the value of each character by 1. So if "zab" was transposed by 1, it'll be "abc".
However for some reason my function picks and chooses what goes in the if statement and I don't know why.
The idea behind my code is:
Let's take "zebra" and a transposition value of 25.
z = 122 on ASCII. 122+25 = 147 which is bigger than 122 so it should go in the if statement. Then the new value should ideally be 96 + the remainder of the transpose value (after it passes z).
However when I run my program the output = ôdaïz
ô = 147 on ascii table (skips if statement)
d = 100 (doesn't skip if statement)
a = 97 (doesn't skip if statement)
ï = 139 (skips if statement)
z = 122 (doesn't skip if statement)
So again.. I reiterate, why does my function pick and choose what goes in the if statement? What am I not seeing?
char* transposition(char* userInput, int transpose){
int temp;
for(int value = 0; value < strlen(userInput); value++){
userInput[value] +=transpose;
if(userInput[value] > 122){
temp = userInput[value] - 122;
userInput[value] = 96+temp;
}
}
return (userInput);
}