diff --git a/otp.c b/otp.c index fdfa262..6558743 100644 --- a/otp.c +++ b/otp.c @@ -132,41 +132,41 @@ int main(int argc, char* argv[]) { } int interactive_mode(void) { - // printf("\n\n\n\n=== OTP Cipher %s ===\n\n", get_version()); + char input[10]; while (1) { show_main_menu(); - char input[10]; - if (fgets(input, sizeof(input), stdin)) { - char choice = toupper(input[0]); - - switch (choice) { - case 'T': - handle_text_encrypt(); - break; - case 'F': - handle_file_encrypt(); - break; - case 'D': - handle_decrypt_menu(); - break; - case 'P': - handle_pads_menu(); - break; - case 'X': - case 'Q': - printf("Goodbye!\n"); - return 0; - default: - printf("Invalid option. Please select T, F, D, P, or X.\n"); - continue; - } - } else { - printf("Error reading input. Please try again.\n"); - continue; + + if (!fgets(input, sizeof(input), stdin)) { + printf("Goodbye!\n"); + break; + } + + char choice = toupper(input[0]); + + switch (choice) { + case 'T': + handle_text_encrypt(); + break; + case 'F': + handle_file_encrypt(); + break; + case 'D': + handle_decrypt_menu(); + break; + case 'P': + handle_pads_menu(); + break; + case 'X': + printf("Goodbye!\n"); + return 0; + default: + printf("Invalid choice. Please try again.\n"); + break; } - printf("\n"); } + + return 0; } int command_line_mode(int argc, char* argv[]) {