2
I created a Music Player for a Data Structure discipline using Double Chained and Circular List. However, you are showing some errors and I am not seeing where. Could someone help me ? Maybe it’s logic error and/or syntax error.
The play option shows the name of the current song and moves to the next one. showPlaylist shows all 7 songs that the playlist contains.
#include <stdio.h>
#include <stdbool.h>
#include <locale.h>
#include <string.h>
typedef struct Music {
char name[25];
struct Music *previous;
struct Music next;
} music;
music *playlist;
void start(){
music *m1=malloc (sizeof(music));
strcpy(m1->name, "MUSIC1");
playlist = m1;
music *m2=(music *)malloc (sizeof(music));
strcpy(m2->name, "MUSIC2");
m1->next = m2;
m2->previous = m1; //ERRO2
music *m3=(music *)malloc (sizeof(music));
strcpy(m3->name, "MUSIC3");
m2->next = m3;
m3->previous = m2;
music *m4=(music *)malloc (sizeof(music));
strcpy(m4->name, "MUSIC4");
m3->next = m4;
m4->previous = m3;
music *m5=(music *)malloc (sizeof(music));
strcpy(m5->name, "MUSIC5");
m4->next = m5;
m5->previous = m4;
music *m6=(music *)malloc (sizeof(music));
strcpy(m6->name, "MUSIC6");
m5->next = m5;
m6->previous = m5;
music *m7=(music *)malloc (sizeof(music));
strcpy(m7->name, "MUSIC7");
m6->next = m7;
m7->previous = m6;
m7->next = m1;
m1->previous = m7;
}
void play(){
printf("%s\n",playlist->name);
playlist=playlist->next;
}
void showPlaylist(){
music *aux = playlist;
int i = 1;
while (i<=7){
printf("%s\n",aux->name);
aux = aux->next;
i++;
}
}
void main(){
setlocale(LC_ALL, "Portuguese");
int op;
start();
do
{
printf("1 - Play music\n");
printf("2 - Show Playlist\n");
printf("0 - Exit\n");
printf("Choose Option:");
scanf("%d",op);
int n;
switch(op) {
case 1: play();
case 2: showPlaylist();
break;
case 0: printf("Byee!\n");
break;
default: printf("What?!\n");
}
} while (op!=0);
}
Many mistakes of mine due to lack of attention. Thanks Adriano for the revision in the code and for the help. I’m slowly improving.
– spw