0
struct songs
{
    char* name[MAX];
    double length;
    struct songs *next;
};
typedef struct songs songs;

struct albums
{
    char* title[MAX];
    int year;
    char* singerName[MAX];
    songs songs;
    struct albums *next;
};

struct albums *head = NULL;
struct albums *curr = NULL;
struct songs *bas=NULL;
struct songs *current=NULL;

我定义了结构。第二部分包含所有专辑的列表。第一部分包含歌曲列表。专辑中有歌曲。

void add(char albumTitle[],char singerName[], int releaseYear )
{
    struct albums *temp;
    temp=(struct albums *)malloc(sizeof(struct albums));
    strcpy( temp->title, albumTitle );
    temp->year=releaseYear;
    strcpy( temp->singerName, singerName );
    if (head== NULL)
    {
    curr=head=temp;
    head->next=NULL;
    curr->next=NULL;
    }
     else
    {
     curr->next=temp;
     curr=temp;
    }

    printf("Done\n");
}

这部分用于添加相册。最后,

void addSong(char albumTitle[],char songName[], double songLength )
{
    struct albums *temp;
    temp=(struct albums *)malloc(sizeof(struct albums));
    temp=head;

    struct songs *tempsong;
    tempsong=(struct songs *)malloc(sizeof(struct songs));
    tempsong=bas=current;
    while(temp!=NULL)
    {
        if(!(strcmp(temp->title, albumTitle)))
        {
            bas=temp->songs;                
            strcpy(tempsong->name,songName);
            tempsong->length=songLength;
                if (bas== NULL)
                {
                bas=tempsong;
                bas->next=NULL;
                current->next=NULL;
                }
                 else
                {
                 current->next=tempsong;
                 current=tempsong;
                }
            break;    
        }
        else
        {
            temp= temp->next;
        }
    }

}

这部分需要为专辑添加歌曲。我的问题在这部分。如何在大链表中添加歌曲?非常感谢您的任何建议,

4

1 回答 1

1

您可以使用与添加专辑相同的技术。没有区别。使用gdb或任何其他调试器来单步调试代码(break main、和gdbrun中的命令),打印出数据的状态(在 gdb 中)并查看问题所在。nextstepprint

请参阅:https ://sourceware.org/gdb/current/onlinedocs/gdb/

于 2013-10-15T01:00:13.000 回答