Hello guys ! Hope you're doing well.
I have faced a problem in declaring linked lists inside a linked list.
I made a picture because it speaks more than 1000 words
Here's my structure declaration:
But, the program won't compile because it generates an error in insert-function.Code:typedef struct author *link; struct author { char name[20]; link next; link down; }; typedef link LIST; typedef link pos_author; typedef struct book *ptr; struct book { char tittle[20]; int year; int page; ptr down; }; typedef ptr pos_book;
cannot convert `author*' to `book*' in assignment
cannot convert `book*' to `author*' in assignment
Here is the Inserting Function:
Code:void insert(LIST L) { char ch; do{ printf("Author: "); pos_author tmp=(pos_author)malloc(sizeof(struct author); scanf("%s",tmp->name); tmp->next=NULL; do{ printf("Book: "); pos_book temp=(pos_book)malloc(sizeof(struct book)); scanf("%s %d %d",temp->tittle,&temp->year,&temp->page); temp->down=NULL; temp->down=tmp->down; // EROOR tmp->down=temp; //ERROR printf("\nAnother Book: [Y/N] "); ch=getch();}while(ch=='Y'||ch=='y'); tmp->next=L->next; L->next=tmp; printf("Another Author: [Y/N] "); ch=getch();}while(ch=='Y'||ch=='y'); }
Looking forward to get an answer from you. Thanx in advance.



4Likes
LinkBack URL
About LinkBacks



