commit 087912bfaaeee0f32f7396d2ca0790c958143ea8
parent b95a9106e7cfaab031574101e65bc5439f3232b7
Author: dwrz <dwrz@dwrz.net>
Date: Wed, 15 May 2019 01:54:11 +0000
Update c/beer-song verse
Diffstat:
1 file changed, 27 insertions(+), 23 deletions(-)
diff --git a/c/beer-song/src/beer_song.c b/c/beer-song/src/beer_song.c
@@ -1,36 +1,40 @@
#include <stdio.h>
-void verse(char* response, int bottles) {
+int verse(char* response, int bottles) {
if (bottles < 0) {
- return;
+ return 0;
}
switch (bottles) {
case 0:
- sprintf(response,
- "No more bottles of beer on the wall, no more bottles of beer.\n"
- "Go to the store and buy some more, "
- "99 bottles of beer on the wall.\n");
- return;
+ return sprintf(response,
+ "No more bottles of beer on the wall, "
+ "no more bottles of beer.\n"
+ "Go to the store and buy some more, "
+ "99 bottles of beer on the wall.\n");
+
case 1:
- sprintf(response,
- "1 bottle of beer on the wall, 1 bottle of beer.\n"
- "Take it down and pass it around, "
- "no more bottles of beer on the wall.\n");
- return;
+ return sprintf(response,
+ "1 bottle of beer on the wall, "
+ "1 bottle of beer.\n"
+ "Take it down and pass it around, "
+ "no more bottles of beer on the wall.\n");
+
case 2:
- sprintf(response,
- "2 bottles of beer on the wall, 2 bottles of beer.\n"
- "Take one down and pass it around, "
- "1 bottle of beer on the wall.\n");
- return;
+ return sprintf(response,
+ "2 bottles of beer on the wall, "
+ "2 bottles of beer.\n"
+ "Take one down and pass it around, "
+ "1 bottle of beer on the wall.\n");
+
default:
- sprintf(response,
- "%d bottles of beer on the wall, %d bottles of beer.\n"
- "Take one down and pass it around, "
- "%d bottles of beer on the wall.\n",
- bottles, bottles, bottles - 1);
- return ;
+ return sprintf(response,
+ "%d bottles of beer on the wall, "
+ "%d bottles of beer.\n"
+ "Take one down and pass it around, "
+ "%d bottles of beer on the wall.\n",
+ bottles, bottles, bottles - 1);
+
}
}