From 4571c0408d30bf35b4adc72b8555005a597f91c0 Mon Sep 17 00:00:00 2001 From: sadeem_albir <142955101+sadeem-albir@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:14:59 +0300 Subject: [PATCH 1/3] Update reverse.c Reset the static variables after the reversing process was complete so the reverse function can be used more than once without issue. --- chapter_4/exercise_4_13/reverse.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/chapter_4/exercise_4_13/reverse.c b/chapter_4/exercise_4_13/reverse.c index b0da222..0f3c64c 100644 --- a/chapter_4/exercise_4_13/reverse.c +++ b/chapter_4/exercise_4_13/reverse.c @@ -27,6 +27,11 @@ void reverse(char str[]) str[j++] = c; } + if (s[j] == '\0') // if whole reverse process is complete, reset the static variables to make this function reusable + { + i = 0; + j = 0; + } } // NOTE: As a simple observation when recursive functions are used, static From d50ea33bcf60adf5bba3cd7878b751a52cfd4725 Mon Sep 17 00:00:00 2001 From: sadeem_albir <142955101+sadeem-albir@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:47:24 +0300 Subject: [PATCH 2/3] Update reverse.c Reset static variables after string-reverse process completed, making the function reusable --- chapter_4/exercise_4_13/reverse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter_4/exercise_4_13/reverse.c b/chapter_4/exercise_4_13/reverse.c index 0f3c64c..0b04c04 100644 --- a/chapter_4/exercise_4_13/reverse.c +++ b/chapter_4/exercise_4_13/reverse.c @@ -27,7 +27,7 @@ void reverse(char str[]) str[j++] = c; } - if (s[j] == '\0') // if whole reverse process is complete, reset the static variables to make this function reusable + if (str[j] == '\0') // if whole reverse process is complete, reset the static variables to make this function reusable { i = 0; j = 0; From 2c1b8e6e65645090aacd47d356b57eba42ff37b7 Mon Sep 17 00:00:00 2001 From: Daniel Costrasel Date: Tue, 5 Mar 2024 20:28:54 +0100 Subject: [PATCH 3/3] Update reverse.c --- chapter_4/exercise_4_13/reverse.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/chapter_4/exercise_4_13/reverse.c b/chapter_4/exercise_4_13/reverse.c index 0b04c04..35236b5 100644 --- a/chapter_4/exercise_4_13/reverse.c +++ b/chapter_4/exercise_4_13/reverse.c @@ -27,11 +27,13 @@ void reverse(char str[]) str[j++] = c; } - if (str[j] == '\0') // if whole reverse process is complete, reset the static variables to make this function reusable + + // if whole reverse process is complete, reset the static variables to make this function reusable + if (str[j] == '\0') { - i = 0; - j = 0; - } + i = 0; + j = 0; + } } // NOTE: As a simple observation when recursive functions are used, static