Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned int stringToGenre(const char *str) {
- // given encoded genre, write string to str (caller must make sure there's enough space)
- // if no error, returns ptr to string; if error, returns NULL (str may have been changed)
- // resulting string must list genres in alphabetical order, separated by comma and a single space
- char teststr[200];
- int counter;
- unsigned int Oars;
- int firstcode = 0;
- int sumstodo[15];
- //teststr = str;
- strcpy(teststr, str);
- //start capilization killer
- while(teststr[counter] != '\n'){
- if ((teststr[counter] > 0x40) && (teststr[counter] < 0x5B)){
- teststr[counter] = teststr[counter] + 32;
- }
- counter++;
- }
- /*#define BLUES_STR "Blues"
- #define CLASSICAL_STR "Classical"
- #define ELECTRONIC_STR "Electronic"
- #define FOLK_COUNTRY_STR "Folk & Country"
- #define FUNK_SOUL_STR "Funk / Soul"
- #define HIP_HOP_STR "Hip Hop"
- #define JAZZ_STR "Jazz"
- #define LATIN_STR "Latin"
- #define POP_STR "Pop"
- #define REGGAE_STR "Reggae"
- #define ROCK_STR "Rock"
- #define STAGE_SCREEN_STR "Stage & Screen"
- */
- // at this point there should be no caps in teststr
- //now to strstr compare to these
- //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
- sumstodo[0] = strstr(teststr, "blues");
- sumstodo[1] = strstr(teststr, "classical");
- sumstodo[2] = strstr(teststr, "electronic");
- sumstodo[3] = strstr(teststr, "folk & country");
- sumstodo[4] = strstr(teststr, "funk / soul");
- sumstodo[5] = strstr(teststr, "hip hop");
- sumstodo[6] = strstr(teststr, "jazz");
- sumstodo[7] = strstr(teststr, "latin");
- sumstodo[8] = strstr(teststr, "pop");
- sumstodo[9] = strstr(teststr, "reggae");
- sumstodo[10] = strstr(teststr, "rock");
- sumstodo[11] = strstr(teststr, "stage & screen");
- if(sumstodo[0] != 0) {
- if(firstcode == 0){
- firstcode = 1;
- Oars = BLUES;
- }
- }
- if(sumstodo[1] != 0) {
- if(firstcode == 1){
- Oars = Oars | CLASSICAL;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = CLASSICAL;
- }
- }
- if(sumstodo[2] != 0) {
- if(firstcode == 1){
- Oars = Oars | ELECTRONIC;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = ELECTRONIC;
- }
- }
- if(sumstodo[3] != 0) {
- if(firstcode == 1){
- Oars = Oars | FOLK_COUNTRY;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = FOLK_COUNTRY;
- }
- }
- if(sumstodo[4] != 0) {
- if(firstcode == 1){
- Oars = Oars | FUNK_SOUL;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = FUNK_SOUL;
- }
- }
- if(sumstodo[5] != 0) {
- if(firstcode == 1){
- Oars = Oars | HIP_HOP;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = HIP_HOP;
- }
- }
- if(sumstodo[6] != 0) {
- if(firstcode == 1){
- Oars = Oars | JAZZ;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = JAZZ;
- }
- }
- if(sumstodo[7] != 0) {
- if(firstcode == 1){
- Oars = Oars | LATIN;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = LATIN;
- }
- }
- if(sumstodo[8] != 0) {
- if(firstcode == 1){
- Oars = Oars | POP;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = POP;
- }
- }
- if(sumstodo[9] != 0) {
- if(firstcode == 1){
- Oars = Oars | REGGAE;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = REGGAE;
- }
- }
- if(sumstodo[10] != 0) {
- if(firstcode == 1){
- Oars = Oars | ROCK;
- }
- if(firstcode == 0){
- firstcode = 1;
- Oars = ROCK;
- }
- }
- if(sumstodo[11] != 0) {
- if(firstcode == 1){
- Oars = Oars | STAGE_SCREEN;
- }
- if(firstcode == 0){
- //firstcode = 1;
- Oars = STAGE_SCREEN;
- }
- }
- return Oars;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement