2013-10-15 2 views
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; 

두 번째 부분은 모든 앨범의 목록을 보유하고 있습니다. 첫 번째 부분에는 노래 목록이 있습니다. 앨범에는 노래가 있습니다. 이 부분은 마지막으로 album.And을 추가 사용중첩 된 LinkedList in c

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

} 

이 부분이 part.How에 내가 큰 노래를 추가 할 수있다 albums.My 문제에 대한 노래를 추가 할 필요가 linkedlist? 의견을 보내 주셔서 감사합니다.

+2

https://sourceware.org/gdb/current/onlinedocs/gdb/ 그냥 당신이'숯불 * 이름은 [MAX는]''MAX' 문자열, MAX' '길이없는 문자열의 배열입니다, 알려. –

+0

Okey @ BrendanLong. 감사합니다. – Semih

답변

1

앨범 추가시 사용한 것과 동일한 기술을 사용할 수 있습니다. 차이점이 없습니다. gdb 또는 다른 디버거를 사용하여 코드 (break main, run, nextstep 명령 gdb)를 실행하고 데이터 상태 (gdb에서 print)를 인쇄하고 잘못된 것을 확인하십시오.

참조 :

+0

네가 맞습니다. 나는 너처럼 생각해. 그리고 나는이 코드를 썼어.하지만 내가 편집 할 때, 작동하지 않았어. – Semih

+1

@Semih 정확하게 작동하지 않는 것에 대해 더 구체적으로 설명해야합니다. –

+0

@Semih 오류 메시지와 함께 작동하지 않는 코드를 표시해야합니다. –