From e9028581aaad0dda9b74e911a493ee404c0ff511 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Wed, 21 Sep 2022 15:43:19 +0200 Subject: [PATCH] output string in uppercase --- caesar_cipher.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/caesar_cipher.c b/caesar_cipher.c index 62bfbc3..bf56fa7 100644 --- a/caesar_cipher.c +++ b/caesar_cipher.c @@ -25,17 +25,35 @@ typedef struct { TextInput* text_input; TextBox* text_box; char input[TEXT_BUFFER_SIZE]; + char upper[TEXT_BUFFER_SIZE]; } CaesarState; +static void string_to_uppercase(const char* input, char* upper) { + int i; + for (i=0; input[i] != '\0'; i++) { + if (input[i] >= 'a' && input[i] <= 'z') { + upper[i] = input[i] - 32; + } else { + upper[i] = input[i]; + } + } + upper[i] = '\0'; +} + static void text_input_callback(void* ctx) { - const CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25); + CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25); FURI_LOG_D("caesar_cipher", "Input text: %s", caesar_state->input); - text_box_set_text(caesar_state->text_box, caesar_state->input); + // this is where we build the output. + //char upper[TEXT_BUFFER_SIZE]; + string_to_uppercase(caesar_state->input, caesar_state->upper); + FURI_LOG_D("caesar_cipher", "Upper text: %s", caesar_state->upper); + text_box_set_text(caesar_state->text_box, caesar_state->upper); view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 1); release_mutex((ValueMutex*)ctx, caesar_state); } + static bool back_event_callback(void* ctx) { const CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25); view_dispatcher_stop(caesar_state->view_dispatcher);