Hey guys!
This is one of those end-of-year deals, so I am getting over my head trying to learn some new things to impress the teacher. We have not gone over strings yet, but for the code I have it seems that woul be the best choice to use. However, when I run the code I am not allowed to type spaces or it drops off. So, I tried changeing the cut off option at new line, but I get junk in remaining spaces to 30!! Can someone give some advice on how to fix it to allow spaces?
Thanks in advance!
CJ
Code:#include <stdio.h> #define N 30 main() { char orig_text[N]; int i = 0, choice = 0; printf("\nThis program allows you to encrypt/decrypt"); printf(" lines of text under %d characters. \n", N); printf("---------------------------------------------------"); printf("-----------------------------"); printf("Please enter a number: 1-Encrypt, 2-Decrypt,"); printf(" 3-Exit: "); while ( scanf("%d", &choice) == choice < 1 || choice > 3) { printf("\nThat is not a valid option!! 1-Encrypt, 2-Decrypt,"); printf(" 3-Exit: "); } if (choice == 1) { { printf("Please enter the text you wish to encrypt: "); scanf("%s", orig_text); } while ( orig_text[i] != '\0' ) { orig_text[i] = orig_text[i] + 3; i++; } printf("Your encrypted text is: %s \n", orig_text); return; } // End of choice 1 'if' statement if ( choice == 2 ) { { printf("Please enter the text you wish to decrypt: "); scanf("%s", orig_text); } while ( orig_text[i] != '\0' ) { orig_text[i] = orig_text[i] - 3; i++; } printf("Your decrypted text is: %s \n", orig_text); return; } // End of choice 2 'if' statement else printf("\nThank you for using my encryption program! Have a nice day!\n"); } // End of main statement



LinkBack URL
About LinkBacks



), however it does not break after I press enter. It actually does the exact opposite and keeps letting the user input values!
by asking you to explain. Cuz you have really already went out of your way to help. I just don't wanna turn something in that I don't understand!