Im programming a tiny music player for school project. And our teacher tell us we have to use linked list.
But i have this crash in my program without warnings, my function Afficher_Liste is working fine (its a function to view my linked list)
My structure which define a music
typedef struct Piste{
char *pTitle;
char *pArtist;
char *pPath;
struct Piste *pNext;
struct Piste *pPrev;
}Piste;
My function :
void Play_Music(Piste **pHead){
int choice;
int ctr = 1;
char * path_music;
path_music= (char*)malloc(200 * sizeof(char));
View_List(&ppDL);
Piste *pCur = *pHead;
printf("What music you want to play ?");
scanf("%d",&choice);
while(choix!=cptr){
pCur = pCur->pNext;
ctr ;
if(choice==cptr){
path_music= pCur->pPath;
}
}
printf("your choice is %s",path_music);
scanf("%d",choice);
}
Edit : the call of the function
void User_Mode(){
int choice;
char *search= NULL;
while(choice!= 4)
{
system("cls");
printf("---------- User Menu----------\n\n");
printf("1 - Search\n");
printf("2 - Play a music\n");
printf("3 - Back to menu\n");
printf("your choice?\n");
scanf("%d", &choice);
switch(choice){
case 1:
fflush(stdin);
search = (char*)malloc(200 * sizeof(char));
printf( "what do you want to listen ? : \n" );
scanf( "%[^\n]", seach);
fgetc( stdin );
if(search!=NULL){
search_music(search,&ppDL);
}
break;
case 2:
play_music();
break;
case 3:
main_menu();
break;
default:
system("cls");
printf("your choice isnt good\n\n");
user_mode();
}
}
}
Edit2 : tried to translate my code
CodePudding user response:
Change your case statement to
case 2:
play_music( &ppDL );
break;