1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
   |  
#include <stdio.h>
#include <stdlib.h>
 
typedef struct 	client
{
  char *login;
  char *passwd;
  int fd;
  struct client *suivant;
}	       	client;
 
void		ajouter_client (client** p, char log[16], char mdp[16], int fd)
{
  client*	new;
 
  new = malloc(sizeof(*new));
  new->login = log;
  new->passwd = mdp;
  new->fd = fd;
  new->suivant = *p;                                  // tu places ton nouvel element devant l'actuel premier
  *p = new;                                                 // il devient l'actuel premier
  return;
}
 
int			display_list(client *list)
{
  client		*current;
 
  current = list;
  while (current)
    {
      printf("%s, %s\n", current->login, current->passwd);
      current = current->suivant;
    }
  return (0);
}
 
int			main(void)
{
   client		*mes_clients;
 
   mes_clients = NULL;
   ajouter_client(&mes_clients,"Momo", "Toto",5);
   ajouter_client(&mes_clients,"Delphine", "Talaron", 42);
   ajouter_client(&mes_clients,"His_log", "His_passwd", 21);
   ajouter_client(&mes_clients,"The_fourth_one", "xxxx", 84);
   ajouter_client(&mes_clients,"Last", "youwillneverfindit", 31415);
   display_list(mes_clients);
   return (0);
} | 
Partager