Cześć Wam!
Problem polega na tym, że wyświetlana jest tylko ostatnio dodana zawartość, a reszta, to jakieś krzaki...
Wskazówki będą bardzo mile widziane :-)
#include <stdio.h>
#include <stdlib.h>
struct Element
{
char *Text;
struct Element *next;
};
void dodaj (struct Element *lista)
{
struct Element *wsk, *nowy;
wsk = lista;
char buf[BUFSIZ];
printf("No dawaj: ");
fgets(buf, (int)sizeof(buf), stdin);
while (wsk->next != NULL) {
wsk = wsk->next;
}
nowy = malloc (sizeof(struct Element));
nowy->Text = buf;
nowy->next = NULL;
wsk->next = nowy;
}
void wypisz(struct Element *lista)
{
struct Element *wsk=lista;
while( wsk != NULL ){
printf ("%s\n", wsk->Text);
wsk = wsk->next;
}
}
int main(void)
{
struct Element *lista;
lista = malloc (sizeof(struct Element));
lista->next=NULL;
dodaj(lista);
dodaj(lista);
wypisz(lista);
return 0;
}