Ho sviluppato questo codice, che crea un albero binario di ricerca con le stringhe e lo stampa. Ora, va in segmentation e core dump, e non trovo davvero l'errore...
Questo è il codice:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 21

typedef struct albero_s_t{
char *v;
struct albero_s_t *dx;
struct albero_s_t *sx;
}albero_s;

char* leggi_stringa(void);
albero_s* ins_ord_stringhe(albero_s *s, char *stringa);
void Stampa_stringhe(albero_s *s);

int main(void){
char *s;
albero_s *tree;

s = malloc(sizeof(char) * N);
s = leggi_stringa();
while(s != EOF){
tree = ins_ord_stringhe(tree, s);
s = leggi_stringa();
}

Stampa_stringhe(tree);

return 0;
}

char* leggi_stringa(void){
char *s;
s = malloc(sizeof(char) * N);
printf("Inserisci una stringa: ");
s = fgets(s, 20, stdin);

return s;
}

albero_s* ins_ord_stringhe(albero_s *s, char *stringa){

if(s==NULL){
s = malloc(sizeof(char));
s->v = stringa;
s->dx = NULL;
s->sx = NULL;
}

if(strcmp(stringa, s->v) <= 0)
s->sx = ins_ord_stringhe(s->sx, stringa);

else
s->dx = ins_ord_stringhe(s->dx, stringa);

return s;
}

void Stampa_stringhe(albero_s *s){

Stampa_stringhe(s->sx);
printf("%s", s->v);
Stampa_stringhe(s->dx);

}