#include <stdlib.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gprintf.h>

/* EXO 5.1 */


typedef struct etud {
  GString* nom;
  GString* pre;
  GString* num;
}Etud;

Etud* create_etud(){
  gchar *str;
  GIOChannel *channel = g_io_channel_unix_new (STDIN_FILENO);

  Etud* pEtud = g_new(Etud,1);
  g_io_channel_read_line (channel, &str, NULL, NULL, NULL);
  pEtud->nom = g_string_new(str);
  g_io_channel_read_line (channel, &str, NULL, NULL, NULL);
  pEtud->pre = g_string_new(str);
  g_io_channel_read_line (channel, &str, NULL, NULL, NULL);
  pEtud->num = g_string_new(str);
  return pEtud;
}


void afficher_list(GList *list){
  GList *l = g_list_first(list);
  for (l = list; l != NULL; l = l->next){
    Etud* e = l->data;
    g_print(" Nom : %s \n", e->nom->str);
    g_print(" Pom : %s \n", e->pre->str);
    g_print(" Num : %s \n", e->num->str);
    g_print(" === \n");
  }
  
}

int main(int argc, char* argv[]){
  g_printf(" === EXO 5.1  === \n");

  GList *lst = NULL ,*l ;

  for(guint8 i = 0; i<3 ;i++){
    g_print(" Saisir etudiant Num : %d \n", i+1);
    Etud*  elem = create_etud();
    lst = g_list_append (lst, elem);
  }
 
  afficher_list(lst); 
  
  return EXIT_SUCCESS;
}
