Sha256: 5cba25a47cabfa6a43d1e0df99964f2168a4538ac6bd3807798d6fbd48b93c9b

Contents?: true

Size: 1.72 KB

Versions: 108

Compression:

Stored size: 1.72 KB

Contents

#include "beer_song.h"
#include <stdio.h>
#include <string.h>

static unsigned int get_verse(char *buffer, unsigned int verse_number)
{
   unsigned int bytes_written = 0;

   if (verse_number == 0) {
      bytes_written =
          sprintf(buffer,
                  "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");
   } else if (verse_number == 1) {
      bytes_written =
          sprintf(buffer,
                  "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");
   } else if (verse_number == 2) {
      bytes_written =
          sprintf(buffer,
                  "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");
   } else if (verse_number <= 99) {
      bytes_written =
          sprintf(buffer,
                  "%u bottles of beer on the wall, %u bottles of beer.\n"
                  "Take one down and pass it around, %u bottles of beer on the wall.\n",
                  verse_number, verse_number, verse_number - 1);
   }

   return bytes_written;
}

void verse(char *buffer, unsigned int verse_number)
{
   (void)get_verse(buffer, verse_number);
}

void sing(char *buffer, unsigned int starting_verse_number,
          unsigned int ending_verse_number)
{
   char *current_position = buffer;

   for (unsigned int i = starting_verse_number + 1; i > ending_verse_number;
        i--) {
      current_position += get_verse(current_position, i - 1);
      strcpy(current_position, "\n");
      current_position++;
   }

   strcpy(current_position - 1, "\0");
}

Version data entries

108 entries across 108 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.179 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.178 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.177 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.176 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.175 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.174 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.173 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.172 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.171 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.170 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.169 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.167 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.166 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.165 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.164 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.163 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.162 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.161 tracks/c/exercises/beer-song/src/example.c
trackler-2.2.1.160 tracks/c/exercises/beer-song/src/example.c