Skip to content

Commit 4571c04

Browse files
authored
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.
1 parent 933e245 commit 4571c04

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

chapter_4/exercise_4_13/reverse.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ void reverse(char str[])
2727

2828
str[j++] = c;
2929
}
30+
if (s[j] == '\0') // if whole reverse process is complete, reset the static variables to make this function reusable
31+
{
32+
i = 0;
33+
j = 0;
34+
}
3035
}
3136

3237
// NOTE: As a simple observation when recursive functions are used, static

0 commit comments

Comments
 (0)