Advertisement
B1KMusic

lyrics generator

Nov 4th, 2016
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.06 KB | None | 0 0
  1. /*
  2.  * For: https://youtu.be/1zxFuMawrDc
  3.  *
  4.  * To use this, you'll need three files in the same directory as the
  5.  * executable: cake.txt, pirate.txt and one.txt
  6.  *
  7.  * The files should be filled with the lyrics to Crazy Cake,
  8.  * You Are a Pirate, and We Are Number One, respectively.
  9.  *
  10.  * Some lyrics are provided at the end of this file
  11.  */
  12. #include <stdio.h>
  13. #include <string.h>
  14.  
  15. FILE *fs[3];
  16. size_t ftracker = 0;
  17.  
  18. int
  19. chcmpi(char ch1, char ch2)
  20. {
  21.     if(ch1 >= 'A' && ch1 <= 'Z')
  22.         ch1 += 32;
  23.  
  24.     if(ch2 >= 'A' && ch2 <= 'Z')
  25.         ch2 += 32;
  26.  
  27.     return ch1 == ch2;
  28. }
  29.  
  30. // case-insensitive implementation of strchr
  31. int
  32. strchri(char *str, char chr)
  33. {
  34.     while(*str)
  35.         if(chcmpi(*(str++), chr))
  36.             return 1;
  37.  
  38.     return 0;
  39. }
  40.  
  41. // case-insensitive implementation of strncmp but it returns a boolean instead of an error code
  42. int
  43. strncmpi(const char *str1, const char *str2, size_t len)
  44. {
  45.     for(size_t i = 0; i < len; i++)
  46.         if(!chcmpi(str1[i], str2[i]))
  47.             return 0;
  48.  
  49.     return 1;
  50. }
  51.  
  52. void
  53. ban(size_t selfilen)
  54. {
  55.     if(fs[selfilen]){
  56.         fclose(fs[selfilen]);
  57.         fs[selfilen] = NULL;
  58.     }
  59. }
  60.  
  61. int
  62. getwd(char *wbuf, FILE *f)
  63. {
  64.     int c;
  65.  
  66.     if(f == NULL){
  67.         ftracker++;
  68.         return 0;
  69.     }
  70.  
  71.     while((c = fgetc(f)) != EOF && !strchr(" \n\t\r", c))
  72.         *(wbuf++) = c;
  73.  
  74.     if(c == EOF)
  75.         ban(ftracker % 3);
  76.  
  77.     return 1;
  78. }
  79.  
  80. int
  81. checkwd(char *wbuf)
  82. {
  83.     char *words[] = {"cake", "pirate", "one"};
  84.     char *selword = words[ftracker % 3];
  85.  
  86.     return strncmpi(selword, wbuf, strlen(selword));
  87. }
  88.  
  89. int
  90. all_banned(void)
  91. {
  92.     return fs[0] == NULL && fs[1] == NULL && fs[2] == NULL;
  93. }
  94.  
  95. int
  96. main()
  97. {
  98.     char wbuf[200];
  99.    
  100.     fs[0] = fopen("cake.txt",   "r");
  101.     fs[1] = fopen("pirate.txt", "r");
  102.     fs[2] = fopen("one.txt",    "r");
  103.  
  104.     while(!all_banned()){
  105.         memset(wbuf, 0, 200);
  106.  
  107.         if(!getwd(wbuf, fs[ftracker % 3]))
  108.             continue;
  109.  
  110.         if(checkwd(wbuf))
  111.             ftracker++;
  112.         else
  113.             printf("%s ", wbuf);
  114.     }
  115.  
  116.     return 0;
  117. }
  118.  
  119. /*
  120. Lyrics:
  121.  
  122.     =============================
  123.     === Crazy Cake (cake.txt) ===
  124.     =============================
  125.  
  126. I'll pile on the candy, it's such a pretty sight.
  127. It makes the food taste a dandy, but my tummy hurts all night.
  128. I'll put in some ingredients, but keep the rest for me.
  129. I'm not just disobedient, I'm careful cant you see?
  130.  
  131. It's a piece of cake to bake a pretty cake. If the way is hazy,
  132. You gotta do the cooking by the book. You know you cant be lazy.
  133. Never use a messy recipe, the cake will end up crazy.
  134. If you do the cooking by the book...
  135.  
  136. Then you'll have a cake.
  137. We gotta have it made.
  138. You know that i love cake.
  139. Finally, it's time to make a cake.
  140.  
  141. Making food is just like science, (make a make)
  142. With tools that blend and baste. (make a make)
  143. And every fun appliance,
  144. Gives the food a different taste. (HEY!)
  145.  
  146. It's a piece of cake to bake a pretty cake. If the way is hazy,
  147. You gotta do the cooking by the book. You know you cant be lazy.
  148. Never use a messy recipe, the cake will end up crazy.
  149. If you do the cooking by the book...
  150.  
  151. Then you'll have a cake.
  152. We gotta have it made.
  153. You know that i love cake.
  154. Finally, it's time to make a cake.
  155.  
  156. We gotta have it made.
  157. You know that i love cake.
  158. Finally, it's time to make a...you gotta do the cooking by the book. Cake!
  159.  
  160.     =====================================
  161.     === You Are a Pirate (pirate.txt) ===
  162.     =====================================
  163.  
  164. Do what you want, 'cause a pirate be free,
  165. YOU ARE A PIRATE!
  166. Yar har, fiddle di dee,
  167. Being a pirate is alright to be,
  168. Do what you want 'cause a pirate be free,
  169. You are a pirate!
  170.  
  171. (spoken)You are a pirate!
  172. (crowd)Yay!
  173.  
  174. We've got us a map, (a map!)
  175. To lead us to a hidden box,
  176. That's all locked up with locks! (with locks!)
  177. And buried deep away!
  178.  
  179. We'll dig up the box, (the box!)
  180. We know it's full of precious booty!
  181. Burst open the locks!
  182. And then we'll say HOORAY!
  183.  
  184. (girl's voice)Yar, har, fiddle di dee.
  185. If you love to sail the sea,
  186. You are a pirate!
  187.  
  188. (spoken)Weigh anchooor!
  189.  
  190. Yar har, fiddle di dee,
  191. Being a pirate is alright with me!
  192. Do what you want 'cause a pirate is free,
  193. You are a pirate!
  194. Arr yarr, ahoy and avast,
  195. dinky-dink-dink-a-dinkadefast!
  196. Hang the black flag
  197. At the end of the mast!
  198. You are a pirate!
  199.  
  200. Hahahahaha! (Yay!)
  201.  
  202. We're sailing away (set sail!),
  203. Adventure awaits on every shore!
  204. We set sail and explore (ya-har!)
  205. And run and jump all day (Yay!)
  206. We float on our boat (the boat!)
  207. Until its time to drop the anchor,
  208. Then hang up our coats (aye-aye!)
  209. Until we sail again!
  210.  
  211. (girl's voice)Yar, har, fiddle di dee.
  212. If you love to sail the sea,
  213. You are a pirate!
  214.  
  215. Laaaand ho!
  216.  
  217. Yar har, fiddle di dee,
  218. Being a pirate is alright with me!
  219. Do what you want 'cause a pirate is free,
  220. You are a pirate!
  221.  
  222. (spoken)Yar har, wind at your back, lads,
  223. Wherever you go!
  224.  
  225. (singing)Blue sky above and blue ocean below,
  226. You are a pirate!
  227.  
  228. Hahahahahaha!
  229. (spoken)You are a pirate!
  230. Heh-heh-heh-heh-heh-heh-heh.
  231.  
  232.     ===================================
  233.     === We Are Number One (one.txt) ===
  234.     ===================================
  235.  
  236. Hey! We're Number One Hey! We're Number One
  237. Now listen closely Here's a little lesson in trickery This is going down in history If you wanna be a Villain Number One You have to chase a superhero on the run
  238. Just follow my moves, and sneak around Be careful not to make a sound Shh No, don't touch that!
  239. We're Number One Hey! We're Number One
  240. Ha ha ha Now look at this net, that I have found When I say go, be ready to throw Go! Throw it on him, not me! Uh, let's try something else
  241. Now watch and learn, here's the deal You slip and slide on this banana peel Ha ha ha, gasp! what are you doing!?
  242. ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We're Number One Hey! ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We're Number One ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We're Number One Hey! ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We're Number One Hey! Hey!
  243.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement