int main(void) { /* Declare a struct TPAB and assign it's variable values */ struct Album *TPAB = malloc(sizeof *TPAB); assert(TPAB != NULL); TPAB -> name = "To Pimp a Butterfly"; TPAB -> date = "2015"; TPAB -> artist = "Kendrick Lamar"; /* Declare a struct Pablo and assign it's variable values */ struct Album *Pablo = malloc(sizeof *Pablo); assert(Pablo != NULL); Pablo = (struct Album*)malloc(sizeof(struct Album)); Pablo -> name = "The Life of Pablo"; Pablo -> date = "2016"; Pablo -> artist = "Kanye West"; /* Use a function to print the Album's information */ printAlbum(TPAB); printAlbum(Pablo); return 0; }
int main(int argc, char*argv[]){ int length; Song* album = readAlbum(argv[1], &length); int on = 1; while(on==1) { printAlbum(album, length); int sel; printf("\nEnter 1 to listen to a song\nEnter 2 to change a rating\nEnter 0 to quit\n"); scanf("%d", &sel); char* song = malloc(sizeof(char) * MAXNAMESIZE); switch(sel) { case 1: // If the user enters 1 to listen to a song printf("\nEnter a title:"); scanf("%s", song); if(listenToSong(song, album, length) == -1) printf("unable to find %s\n\n", song); else listenToSong(song, album, length); break; case 2: //if the user enters 2 to rate a song printf("\nEnter a title:"); scanf("%s", song); int rating; printf("Enter a new rating:\n"); scanf("%d", &rating); if(changeRating(song,rating, album, length) == -1) printf("unable to find %s\n\n", song); else changeRating(song,rating, album, length); break; case 0: //if the user chooses to exit the program on = 0; break; } } free(album); return 0; }