Dwie struktury, problem z dodaniem nowego elementu do listy

0

Witam,
mam następujący problem: Nie wiem jak poprawnie przypisać nowemu elementowi w liście wartość typu char. Kompilator w zaznaczonym miejscu kodu wywala następujący bląd: "incompatible types in assignment" Moje wypociny:

/* Struktury uzyte w programie*/

struct ksiazka{
         char tytul[256];
};

struct lista{
        struct lista *next;
        struct ksiazka ks;
};

/* funkcja dodajaca*/
struct lista* dodaj(struct lista* head){
       
       int i;
       char tytul[40];
       struct lista *ogon=head;
       struct lista* nowy=NULL;
       
       //ustawienie ogona na koniec listy
       if(ogon->next != NULL){
                     do{
                              ogon=ogon->next;
                     }while(ogon);
                     
       }
       printf("Podaj tytul ksiazki: ");
       scanf("%s", &tytul);
       struct ksiazka *ks = (struct ksiazka *)malloc(sizeof(struct ksiazka)); 
       
       for(i=0; i<15; i++){
       ks->tytul[i]=tytul[i];
       }
       nowy=(struct lista*)malloc(sizeof(struct lista));
       nowy->ks= ks; //<-----------------------------------------------------------tutaj blad kompilatora
       ogon->next=nowy;
       nowy->next=NULL;
       ogon=nowy;
       
       return head;
       
}
1

Spróbuj:

 
nowy->ks.tytul[256]= ks->tytul[40];
1
       scanf("%s", &tytul);

4p.c:31:8: warning: format '%s' expects type 'char *', but argument 2 has type 'char (*)[40]'
powinno być scanf("%s",tytul);

       nowy->ks= ks; //<-----------------------------------------------------------tutaj blad kompilatora

4p.c:38:16: error: incompatible types when assigning to type 'struct ksiazka' from type 'struct ksiazka *'

1
       scanf("%s", tytul);
       nowy=(struct lista*)malloc(sizeof(struct lista));
       strcpy(nowy->ks.tytul,tytul);
0

Dziękuję za pomoc działa :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1