commit 3393154d15cd0a8fcc0a0713502019ed713cd246
parent 087912bfaaeee0f32f7396d2ca0790c958143ea8
Author: dwrz <dwrz@dwrz.net>
Date: Wed, 15 May 2019 01:54:21 +0000
Update c/beer-song sing
Diffstat:
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/c/beer-song/src/beer_song.c b/c/beer-song/src/beer_song.c
@@ -39,9 +39,19 @@ int verse(char* response, int bottles) {
}
void sing(char *response, int start, int finish) {
+ char *origin = response;
+
for (int i = start; i >= finish; i--) {
- verse(response, i);
+ int charsAdded = verse(response, i);
+ response += charsAdded;
+
+ // Add a newline between verses,
+ // except for the last verse.
+ if (i != finish) {
+ sprintf(response, "\n");
+ response += 1;
+ }
}
- return ;
+ response = origin;
}