int main() { char song[] = "HauntedHouse: d=4,o=5,b=120: 2a4, 2e, 2d#, 2b4, 2a4, 2c, 2d, 2a#4, 2e., e, 1f4, 1a4, 1d#, 2e., d, 2c., b4, 1a4, 1p, 2a4, 2e, 2d#, 2b4, 2a4, 2c, 2d, 2a#4, 2e., e, 1f4, 1a4, 1d#, 2e., d, 2c., b4, 1a4"; char *defaultsstring, *tune; struct defaults defs; defaultsstring = malloc(strlen(song) + 1); // allocate memory for the defaults section of the string if (defaultsstring == NULL){error("Out of memory.");} tune = break_up_string(song, defaultsstring); // break up song into its 3 parts. parse_defaults(defaultsstring,&defs); // parse default string into default struct int count = count_notes(tune, ','); struct note notes[count]; // count notes and allocate array int i = 0; char *currentNote = tune; // while there are notes in the note section, parse them into the array while(!isEmpty(currentNote)){ if (i >= count) {error("Bad Note Section.");} currentNote = parse_note_string(currentNote, &defs, ¬es[i]); i++; } play_tune(notes,defs.bpm, i); // play the song free(defaultsstring); // free memory return 0; }
void urd_update_rankings(struct urd_status *game) { int res = parse_defaults(game); if(res == 1) return; if(res == 2) { generate_begin(game); return; } sprintf(game->output, "Invalid command.\n"); }