Incertitude sur liste chainée ! help please

Résolu/Fermé
Utilisateur anonyme - Modifié par astrocurieux le 27/04/2015 à 13:39
 Utilisateur anonyme - 2 mai 2015 à 10:51
Bonjour ,

j'aimerais crée deux liste chainée distincte l'une de l'autre .
l'une contient un string et 2 integer
l'autre uniquement un string .

j'ai déjà coder deux trois fonctions mais sa ne semble pas fonctionner .
un peu d'aide est-il possible ?

voici les structure qui sont dans mon fichier.h !
typedef struct s_elem
{
  char          *name;
  int           coo_x;
  int           coo_y;
  struct s_elem *next;
}               t_elem;

typedef struct s_list
{
  struct s_elem *first;
}               t_list;

typedef struct  s_way
{
  char          *str;
  struct s_way  *next;
}               t_way;

typedef struct s_wlist
{
  struct s_way  *first;
}               t_wlist;


et voici les fonction qui pause problème

t_wlist         *initiali()
{
  t_wlist       *wlist;
  t_way         *way;

  wlist = malloc(sizeof(*wlist));
  way = malloc(sizeof(*way));
  if (wlist == NULL || way == NULL)
    eromalloc("initiali", 2);
  way->str = NULL;
  way->next = NULL;
  wlist->first = way;
  return (wlist);
}

void    add_element(t_wlist *wlist, char *way)
{
  t_way        *new;

  new = malloc(sizeof(*new));
  if (wlist == NULL || new == NULL)
    eromalloc("add_element", 3);
  new->str = way;
  new->next = wlist->first;
  wlist->first = new;
}


je ne parvient pas a afficher les élément de mes liste ( ici il n'y en a que une du coup )

je le fait via cette fonction
void    aff_list(t_wlist *wlist)
{
  if (wlist == NULL)
    {
      printf("wlist is NULL\n");
      exit (1);
    }
  s_way *actu = wlist->first;
  while (actu != NULL)
    {
      printf("%d -> ", actu->str);
      actu = actu->next;
    }
  printf("NULL\n");
}

1 réponse

chris79 Messages postés 91 Date d'inscription lundi 3 octobre 2005 Statut Membre Dernière intervention 1 février 2016 25
1 mai 2015 à 20:57
Slt,

Il faudrait plus de précision sur l'erreur que tu obtiens.
En tout cas, il n'y a pas de raison de rajouter un element de type t_way dans la fonction
t_wlist         *initiali()
0
Utilisateur anonyme
2 mai 2015 à 10:51
oui effectivement , j'ai fini par trouver une solution seul !
merci de ton intervention ;-)
0