Mam problem po napisaniu dwóch funkcji jednej która wyświetlą naszą liste jedno kierunkową a druga która ma dodawać do tej listy dane. Gdy wczytuje te funkcje w mainie i odpalam program to widzę tylko że program się wykonał a ja nic nie mogłem dalej dodać gdzie jest błąd ? Jakby ktoś mógł podpowiedzieć poza tym jak sortować listę po indeksie lub danych ze structu(nazwa lub email lub tel).
#include <stdio.h>
#include <stdlib.h>
typedef struct klient{
char nazwa[40];
char email[30];
char tel[15];
struct klient * next;
}klient_type ;
void show(klient_type *head)
{
printf("\n");
if(head==NULL) printf("List is empty");
else
{
klient_type *current=head;
do {
printf("%s\n", current->nazwa);
printf("%s\n", current->email);
printf("%s\n", current->tel);
printf("\n");
current = current->next;
}while (current != NULL);
}
}
void dodaj(klient_type *head)
{
klient_type *last = head;
if(head==NULL)
{
head=last->next;
}
while(last->next!=NULL)
{
last=last -> next;
}
last->next = (klient_type*)malloc(sizeof(klient_type));
printf("Podaj nazwe nowego klienta \n");
gets(last->next->nazwa);
printf("Podaj email nowego klienta \n");
gets(last->next->email);
printf("Podaj telefon nowego klienta \n");
gets(last->next->tel);
}
int main()
{
klient_type *head = NULL;
head = (klient_type *)malloc(sizeof(klient_type));
dodaj(head);
show(head);
return 0;
}