Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. unsigned int stringToGenre(const char *str) {
  2. // given encoded genre, write string to str (caller must make sure there's enough space)
  3. // if no error, returns ptr to string; if error, returns NULL (str may have been changed)
  4. // resulting string must list genres in alphabetical order, separated by comma and a single space
  5. char teststr[200];
  6. int counter;
  7. unsigned int Oars;
  8. int firstcode = 0;
  9. int sumstodo[15];
  10. //teststr = str;
  11. strcpy(teststr, str);
  12. //start capilization killer
  13. while(teststr[counter] != '\n'){
  14. if ((teststr[counter] > 0x40) && (teststr[counter] < 0x5B)){
  15. teststr[counter] = teststr[counter] + 32;
  16. }
  17. counter++;
  18. }
  19. /*#define BLUES_STR "Blues"
  20. #define CLASSICAL_STR "Classical"
  21. #define ELECTRONIC_STR "Electronic"
  22. #define FOLK_COUNTRY_STR "Folk & Country"
  23. #define FUNK_SOUL_STR "Funk / Soul"
  24. #define HIP_HOP_STR "Hip Hop"
  25. #define JAZZ_STR "Jazz"
  26. #define LATIN_STR "Latin"
  27. #define POP_STR "Pop"
  28. #define REGGAE_STR "Reggae"
  29. #define ROCK_STR "Rock"
  30. #define STAGE_SCREEN_STR "Stage & Screen"
  31. */
  32. // at this point there should be no caps in teststr
  33. //now to strstr compare to these
  34. //if the string is found, will change the sumtodo array value for itself to the pointer. so it will be non zero. check for that, and then do the ors
  35. sumstodo[0] = strstr(teststr, "blues");
  36. sumstodo[1] = strstr(teststr, "classical");
  37. sumstodo[2] = strstr(teststr, "electronic");
  38. sumstodo[3] = strstr(teststr, "folk & country");
  39. sumstodo[4] = strstr(teststr, "funk / soul");
  40. sumstodo[5] = strstr(teststr, "hip hop");
  41. sumstodo[6] = strstr(teststr, "jazz");
  42. sumstodo[7] = strstr(teststr, "latin");
  43. sumstodo[8] = strstr(teststr, "pop");
  44. sumstodo[9] = strstr(teststr, "reggae");
  45. sumstodo[10] = strstr(teststr, "rock");
  46. sumstodo[11] = strstr(teststr, "stage & screen");
  47.  
  48. if(sumstodo[0] != 0) {
  49. if(firstcode == 0){
  50. firstcode = 1;
  51. Oars = BLUES;
  52. }
  53. }
  54. if(sumstodo[1] != 0) {
  55. if(firstcode == 1){
  56. Oars = Oars | CLASSICAL;
  57. }
  58. if(firstcode == 0){
  59. firstcode = 1;
  60. Oars = CLASSICAL;
  61. }
  62. }
  63. if(sumstodo[2] != 0) {
  64. if(firstcode == 1){
  65. Oars = Oars | ELECTRONIC;
  66. }
  67. if(firstcode == 0){
  68. firstcode = 1;
  69. Oars = ELECTRONIC;
  70. }
  71. }
  72. if(sumstodo[3] != 0) {
  73. if(firstcode == 1){
  74. Oars = Oars | FOLK_COUNTRY;
  75. }
  76. if(firstcode == 0){
  77. firstcode = 1;
  78. Oars = FOLK_COUNTRY;
  79. }
  80. }
  81. if(sumstodo[4] != 0) {
  82. if(firstcode == 1){
  83. Oars = Oars | FUNK_SOUL;
  84. }
  85. if(firstcode == 0){
  86. firstcode = 1;
  87. Oars = FUNK_SOUL;
  88. }
  89. }
  90. if(sumstodo[5] != 0) {
  91. if(firstcode == 1){
  92. Oars = Oars | HIP_HOP;
  93. }
  94. if(firstcode == 0){
  95. firstcode = 1;
  96. Oars = HIP_HOP;
  97. }
  98. }
  99. if(sumstodo[6] != 0) {
  100. if(firstcode == 1){
  101. Oars = Oars | JAZZ;
  102. }
  103. if(firstcode == 0){
  104. firstcode = 1;
  105. Oars = JAZZ;
  106. }
  107. }
  108. if(sumstodo[7] != 0) {
  109. if(firstcode == 1){
  110. Oars = Oars | LATIN;
  111. }
  112. if(firstcode == 0){
  113. firstcode = 1;
  114. Oars = LATIN;
  115. }
  116. }
  117. if(sumstodo[8] != 0) {
  118. if(firstcode == 1){
  119. Oars = Oars | POP;
  120. }
  121. if(firstcode == 0){
  122. firstcode = 1;
  123. Oars = POP;
  124. }
  125. }
  126. if(sumstodo[9] != 0) {
  127. if(firstcode == 1){
  128. Oars = Oars | REGGAE;
  129. }
  130. if(firstcode == 0){
  131. firstcode = 1;
  132. Oars = REGGAE;
  133. }
  134. }
  135. if(sumstodo[10] != 0) {
  136. if(firstcode == 1){
  137. Oars = Oars | ROCK;
  138. }
  139. if(firstcode == 0){
  140. firstcode = 1;
  141. Oars = ROCK;
  142. }
  143. }
  144. if(sumstodo[11] != 0) {
  145. if(firstcode == 1){
  146. Oars = Oars | STAGE_SCREEN;
  147. }
  148. if(firstcode == 0){
  149. //firstcode = 1;
  150. Oars = STAGE_SCREEN;
  151. }
  152. }
  153.  
  154. return Oars;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement