如何选择链表中的项目

朱利安1h

我正在为学校项目编写一个小型音乐播放器。我们的老师告诉我们必须使用链表。

但是我在我的程序中发生了这个崩溃而没有警告,我的函数 Afficher_Liste 工作正常(它是一个查看我的链表的函数)

我定义音乐的结构

typedef struct Piste{
    char *pTitle;
    char *pArtist;
    char *pPath;
    struct Piste *pNext;
    struct Piste *pPrev;
}Piste;

我的功能:

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);
}

编辑:函数的调用

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:试图翻译我的代码

托弗

将您的案例陈述更改为

case 2:
        play_music( &ppDL );
        break;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章