Hey there guys,
I am currently in the process of writing a ceasar shift program for UNI and would really appreciate some advice. I have pretty much finished the program but there are 2 elements that are stumping me at the moment.
Basically the help I need is on the function below:
Code:
void decryptEncryptLine(int shift) {
char input;
char output;
const char SENT = '\n';
printf("Please enter characters to be encrypted/decrypted\n\n");
scanf("%c", &input);
while (input != SENT){ // while input is a character
input = (toupper(input)); // convert lowercase to uppercase
output = input + (shift); // apply ceasar shift
if (output > 90) { // encode wrap around
output -= 26;
}
else if (output < 65) { // decode wrap around
output += 26;
}
printf("%c",output);
scanf("%c", &input);
}
}
the above function takes one input character at a time and applies the ceasar shift then once a "\n" is detected the loop terminates then prints out the shifted characters. The problem I am having is that when it encounters a space, the program shifts the space and I dont want it to. Instead of a space I get the shifted ASCII character. Im not really sure how to go about enabling the user to enter a space and then just print the space with no shift. The other problem that i am having is that I need to use the isalpha() function so that the function will only accept alpha characters. I am also having trouble implementing this. I have tried various ways to incorporate these elements but the out put is never what I want it to be. so far the output looks like this:
i like to eat pizza
N?QNPJ?YT?JFY?UNEEF
Which is correct for the shift but if i try to include these 2 elements the output changes and I end up with everything being displayed up to the first space, then nothing after that. So basically this is as good as I can get it at this stage.
Any help/advice would be hugely appreciated.
Thanks Guys