Witam,
Będę wdzięczny jeśli ktoś zerknie na mój kod. Próbuję napisać program, który dodaje elementy do listy łączonej w funkcji. Większość błędów udało mi się usunąć samemu, jednak nie mam pomysłu jak usunąć coś takiego:
lista.c14: error: request for member ‘nast’ in something not a structure or union
błąd odnosi się do warunku pętli while w funkcji dodaj.
Chętnie posłucham też innych uwag na temat mojego programu. Nie jestem do końca pewny czy nie zawiera innych błędów, których nie zauważył kompilator.
#include <stdio.h>
#include <stdlib.h>
struct lista{
int identyfikator;
struct lista * nast;
};
void inicjuj(struct lista ** wsk);
void dodaj(struct lista ** wsk, int id);
int main(void){
struct lista * glowny;
inicjuj(&glowny);
dodaj(&glowny, 5);
dodaj(&glowny, 10);
return 0;
}
void inicjuj(struct lista ** wsk){
*wsk = NULL;
}
void dodaj(struct lista ** wsk, int id){
struct lista * nowy;
nowy = (struct lista*)malloc(sizeof(struct lista));
nowy -> nast = NULL;
nowy -> identyfikator = id;
if(*wsk == NULL)
*wsk = nowy;
else{
while(*wsk -> nast != NULL)
*wsk = (*wsk) -> nast;
(*wsk) -> nast = nowy;
}
}