Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This is a rough spanish language translation of 99 bottles: http://pastebin.com/Y2BWcRRQ
- */
- #include <stdio.h>
- #include <string.h>
- #define VERSE_1 "%s botella%s de cerveza en la pared, %s botella%s de cerveza.\n"
- #define VERSE_2 "Tomar uno abajo, pasarlo alrededor, o, %s botella%s de cerveza en la pared.\n\n"
- #define VERSE_3 "No mas botellas de cerveza en la pared, no mas botellas de cerveza.\n"
- #define VERSE_4 "Ir a la tienda, comprar un poco mas, noventa y nueve botellas de cerveza en la pared.\n"
- #define SEPARATOR " y "
- const char *ones_dict[] = {"no mas", "uno", "dos", "tres", "cuatro", "sinco", "seis", "siete", "ocho", "nueve"};
- const char *tens_dict[] = {0, 0, "veinta", "trenta", "cuarenta", "sincuenta", "seisenta", "setenta", "ochenta", "nueventa"};
- const char *teens_dict[] = {"diez", "onse", "dose", "trese", "catorse", "quinse", "diez y seis", "diez y siete", "diez y ocho", "diez y nueve"};
- void to_english(char *buf, int bottles);
- int plural(int qty);
- void write_verse(int bottles);
- void
- to_english(char *buf, int bottles)
- {/*{{{*/
- int ones = bottles % 10,
- tens = (bottles - ones) / 10;
- if(bottles == 0){
- strncpy(buf, ones_dict[0], 30);
- } else if(tens == 0){
- strncpy(buf, ones_dict[ones], 30);
- } else if(tens == 1){
- strncpy(buf, teens_dict[ones], 30);
- } else if(ones == 0){
- strncpy(buf, tens_dict[tens], 30);
- } else {
- snprintf(buf, 30, "%s" SEPARATOR "%s", tens_dict[tens], ones_dict[ones]);
- }
- }/*}}}*/
- int
- plural(int qty)
- {/*{{{*/
- return qty != 1;
- }/*}}}*/
- void
- write_verse(int bottles)
- {/*{{{*/
- char numbuf[30] = "";
- to_english(numbuf, bottles);
- printf(VERSE_1, numbuf, plural(bottles) ? "s" : "", numbuf, plural(bottles) ? "s" : "");
- to_english(numbuf, bottles - 1);
- printf(VERSE_2, numbuf, plural(bottles - 1) ? "s" : "");
- if(bottles - 1 == 0){
- printf(VERSE_3 VERSE_4);
- }
- }/*}}}*/
- int
- main()
- {/*{{{*/
- int bottles = 99;
- while(bottles){
- write_verse(bottles);
- bottles--;
- }
- }/*}}}*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement