Modification et suppression

Fermé
timos1 Messages postés 5 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 28 mars 2013 - 20 mars 2013 à 01:23
timos1 Messages postés 5 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 28 mars 2013 - 20 mars 2013 à 13:38
Bonjour,


j'ai besoin de code source ecrit en c de deux fonctions l'un pour modifer une ligne d'une fichier text et l'autre de la supprimer et merciiii :)
A voir également:

2 réponses

fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 842
20 mars 2013 à 07:08
Merci de montrer ce que tu as fait et de nousvdire là où tu bloques on pourra t'aider plus facilement.
0
timos1 Messages postés 5 Date d'inscription mercredi 20 mars 2013 Statut Membre Dernière intervention 28 mars 2013
20 mars 2013 à 13:38
//Inclusion des librairies
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
#include <stdlib.h>

static void modification     (GtkWidget *wid, GtkWidget *wi)
{
  GtkWidget *window;
  GtkWidget *table;
  GtkWidget *label1;
  GtkWidget *label2;
  GtkWidget *entry1;
   GtkWidget *entry2;
 GtkWidget *bouton;


  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_title(GTK_WINDOW(window), "modification ");
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);
  table = gtk_table_new(3, 3, FALSE);
  gtk_container_add(GTK_CONTAINER(window), table);
  label1 = gtk_label_new("Taille personne");
 label2 = gtk_label_new("Poids personne");

  bouton = gtk_button_new_with_label("confirmer");gtk_table_attach(GTK_TABLE(table), bouton, 1, 2, 2, 3,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 3, 3);
  entry1 = gtk_entry_new();
  entry2 = gtk_entry_new();
   gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 3, 3);
   gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 3, 3);
  gtk_table_attach(GTK_TABLE(table), entry1, 1, 2, 0, 1,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 3, 3);
    gtk_table_attach(GTK_TABLE(table), entry2, 1, 2, 1, 2,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 3, 3);


  gtk_widget_show(table);

  gtk_widget_show(label1);
   gtk_widget_show(bouton);

   gtk_widget_show(label2);
  gtk_widget_show(entry1);
  gtk_widget_show(entry2);
  gtk_widget_show(window);
  g_signal_connect(window, "destroy",
      G_CALLBACK(gtk_main_quit), NULL);
}
static void copier2(GtkWidget *widget, GtkEntry **entry2)
{FILE *FP ;
FP=fopen("Fpersonne.txt","a");
fprintf(FP,"\n");

  fprintf (FP,"taille personne: %s",gtk_entry_get_text(entry2));

  fprintf(FP,"\n");

}
static void copier3(GtkWidget *widget, GtkEntry **entry3)
{FILE *FP ;
FP=fopen("Fpersonne.txt","a");
fprintf(FP,"\n");

  fprintf (FP,"poids personne: %s",gtk_entry_get_text(entry3));

  fprintf(FP,"\n");
  fprintf(FP,"\n");
  fprintf(FP ,"********************************************") ;
  fprintf(FP,"\n");

}

static void copier(GtkWidget *widget, GtkEntry **entry1)
{FILE *FP ;
FP=fopen("Fpersonne.txt","a");
fprintf(FP,"\n");

  fprintf (FP,"code persone: %s",gtk_entry_get_text(entry1));

  fprintf(FP,"\n");

}


 static void suppression    (GtkWidget *wid, GtkWidget *wi)
{
  GtkWidget *window;
  GtkWidget *table;
  GtkWidget *label1;
   GtkWidget *bouton;
  GtkWidget *label3;
  GtkWidget *entry1;


  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_title(GTK_WINDOW(window), "creation d'une nouvelle personne");
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);
  table = gtk_table_new(3, 3, FALSE);
  gtk_container_add(GTK_CONTAINER(window), table);
  label1 = gtk_label_new("Code Personne");

  bouton = gtk_button_new_with_label("supprimer") ;
 label3 = gtk_label_new("SAISISSEZ LE CODE DE LA PERSONNE A SUPPRIMER");
  gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 1, 2,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
   gtk_table_attach(GTK_TABLE(table), bouton, 0, 1, 2, 3,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
   gtk_table_attach(GTK_TABLE(table), label3, 0, 2, 0, 1,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
  entry1 = gtk_entry_new();
  gtk_table_attach(GTK_TABLE(table), entry1, 1, 2, 1, 2,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
  gtk_widget_show(table);
  gtk_widget_show(label1);
   gtk_widget_show(bouton);
      gtk_widget_show(label3);
  gtk_widget_show(entry1);
  gtk_widget_show(window);
  g_signal_connect(window, "destroy",
      G_CALLBACK(gtk_main_quit), NULL);
        gtk_signal_connect(GTK_OBJECT(bouton), "clicked", GTK_SIGNAL_FUNC (eff), (GtkEntry*)entry1 );
}

static void MODIFICATION     (GtkWidget *wid, GtkWidget *wi)
{
  GtkWidget *window;
  GtkWidget *table;
  GtkWidget *label1;
  GtkWidget *label2;
  GtkWidget *entry1;
 GtkWidget *bouton;


  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_title(GTK_WINDOW(window), "modification ");
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);
  table = gtk_table_new(3, 3, FALSE);
  gtk_container_add(GTK_CONTAINER(window), table);
  label1 = gtk_label_new("Code Personne");

  bouton = gtk_button_new_with_label("valider");gtk_table_attach(GTK_TABLE(table), bouton, 1, 2, 1, 2,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 3, 3);
  entry1 = gtk_entry_new();
   gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 3, 3);
  gtk_table_attach(GTK_TABLE(table), entry1, 1, 2, 0, 1,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 3, 3);

  gtk_signal_connect(GTK_OBJECT(bouton), "clicked", GTK_SIGNAL_FUNC (modification), (GtkEntry*)entry1 );

  gtk_widget_show(table);

  gtk_widget_show(label1);
   gtk_widget_show(bouton);

   gtk_widget_show(label2);
  gtk_widget_show(entry1);
  gtk_widget_show(window);
  g_signal_connect(window, "destroy",
      G_CALLBACK(gtk_main_quit), NULL);
}

 void CREATION(GtkWidget *widget, gpointer *entry)
{

int n ;


  GtkWidget *window;
  GtkWidget *table;
GtkWidget *entry1,*entry2,*entry3,*entry4 ,*entryn;
  GtkWidget *label1;
  GtkWidget *label2;
  GtkWidget *label3;
    GtkWidget *label4;
     GtkWidget *bouton;








  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_title(GTK_WINDOW(window), "creation d'une nouvelle personne");
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);

  table = gtk_table_new(6, 2, FALSE);
  gtk_container_add(GTK_CONTAINER(window), table);

  label1 = gtk_label_new("Code Personne");
  label2 = gtk_label_new("Taille Personne");
  label3 = gtk_label_new("Poids Personne");
  label4 = gtk_label_new("Voulez-vous ajouter un autre employe O/N");



  gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
      GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
  gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
      GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
  gtk_table_attach(GTK_TABLE(table), label3, 0, 1, 2, 3,
      GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
       gtk_table_attach(GTK_TABLE(table), label4, 0, 1,4 , 5,
      GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);


    entry1 = gtk_entry_new();
     entry2 = gtk_entry_new();
      entry3 = gtk_entry_new(); entry4 = gtk_entry_new();


  gtk_table_attach(GTK_TABLE(table), entry1, 1, 2, 0, 1,
      GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
  gtk_table_attach(GTK_TABLE(table), entry2, 1, 2, 1, 2,
      GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
  gtk_table_attach(GTK_TABLE(table), entry3, 1, 2, 2, 3,
      GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
       gtk_table_attach(GTK_TABLE(table), entry4, 1, 2,4, 5,
      GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
bouton = gtk_button_new_with_label("ajouter");gtk_table_attach(GTK_TABLE(table), bouton, 0, 1, 5, 6,
  GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 5, 5);
  gtk_widget_show(table);

    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), entry1, TRUE, TRUE, 0);

    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), entry2, TRUE, TRUE, 0);

    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), entry3, TRUE, TRUE, 0);

    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), entry4, TRUE, TRUE, 0);






     gtk_signal_connect(GTK_OBJECT(bouton), "clicked", GTK_SIGNAL_FUNC (copier), (GtkEntry*)entry1 );
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->action_area), bouton, TRUE, TRUE, 0);
     gtk_signal_connect(GTK_OBJECT(bouton), "clicked", GTK_SIGNAL_FUNC (copier2), (GtkEntry*)entry2 );
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->action_area), bouton, TRUE, TRUE, 0);
     gtk_signal_connect(GTK_OBJECT(bouton), "clicked", GTK_SIGNAL_FUNC (copier3), (GtkEntry*)entry3 );
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->action_area), bouton, TRUE, TRUE, 0);



  gtk_widget_show(label1);
  gtk_widget_show(label2);
  gtk_widget_show(label3);
   gtk_widget_show(label4);


  gtk_widget_show(entry1);
  gtk_widget_show(entry2);
  gtk_widget_show(entry3);
  gtk_widget_show(entry4);

  gtk_widget_show(bouton);
  gtk_widget_show(window);


g_signal_connect(window, "destroy",
      G_CALLBACK(gtk_main_quit), NULL);
}
 void show_question(GtkWidget *widget, gpointer window)
{
  GtkWidget *dialog;
gint resultat;


  dialog = gtk_message_dialog_new(GTK_WINDOW(window),
            GTK_DIALOG_DESTROY_WITH_PARENT,
            GTK_MESSAGE_QUESTION,
            GTK_BUTTONS_YES_NO,"Are you sure to quit?");
  gtk_window_set_title(GTK_WINDOW(dialog), "??????");
resultat=  gtk_dialog_run(GTK_DIALOG(dialog));
  gtk_widget_destroy(dialog);
if (resultat==GTK_RESPONSE_YES)
{gtk_widget_destroy(window);}
}
 void helloWorld ()
{

  GtkWidget *win = NULL;
  GtkWidget *vbox = NULL;
    GtkWidget *M1;
  GtkWidget *M2;
  GtkWidget *M3;
  GtkWidget *M4;

  win= gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(win), 300,200);
  gtk_window_set_title(GTK_WINDOW(win), "Classification des données selon la méthode de C-Moyennes Floues");
  gtk_container_set_border_width(GTK_CONTAINER(win), 5);
  vbox = gtk_vbox_new (TRUE, 6);
  gtk_container_add (GTK_CONTAINER (win), vbox);
   M1 = gtk_button_new_with_label("creation d'une nouvelle personne");
    M2 = gtk_button_new_with_label("Modification d'une personne existante");
  M3 = gtk_button_new_with_label("Supression d'une personne existante");

  M4 = gtk_button_new_with_label("Quiter");

  gtk_box_pack_start(GTK_BOX(vbox), M1, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), M2, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), M3, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), M4, TRUE, TRUE, 0);

  g_signal_connect (G_OBJECT (M1), "clicked", G_CALLBACK (CREATION), (gpointer) win);

  g_signal_connect (G_OBJECT (M2), "clicked", G_CALLBACK (MODIFICATION), (gpointer) win);
   g_signal_connect (G_OBJECT (M3), "clicked", G_CALLBACK (suppression), (gpointer) win);



  g_signal_connect(G_OBJECT(M4), "clicked",G_CALLBACK(gtk_main_quit), NULL);

  g_signal_connect_swapped(G_OBJECT(win), "destroy",G_CALLBACK(gtk_main_quit), G_OBJECT(win));

  /* Enter the main loop */
  gtk_widget_show_all (win);
  gtk_main ();


}







void client( GtkWidget *win,gpointer data)
{
    GtkWidget *p;




p= gtk_button_new_with_label("CLIENT  _iujf ");
gtk_box_pack_start(GTK_BOX(win), p, TRUE, TRUE, 0);

}
int main (int argc, char *argv[])
{




  GtkWidget *win = NULL;
  GtkWidget *vbox = NULL;
    GtkWidget *M1;
  GtkWidget *M2;
  GtkWidget *M3;
  GtkWidget *M4;

  /* Initialize GTK+ */
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  gtk_init (&argc, &argv);
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

  /* Create the main window */

  gtk_init(&argc, &argv);

  win= gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(win), 480,480);
gtk_window_set_title(GTK_WINDOW(win), "Classification");
  gtk_container_set_border_width(GTK_CONTAINER(win), 5);


  /* Create a vertical box with buttons */
  vbox = gtk_vbox_new (TRUE, 6);
  gtk_container_add (GTK_CONTAINER (win), vbox);
   M1 = gtk_button_new_with_label("Gestion des personnes");
    M2 = gtk_button_new_with_label("Classification CMF");
  M3 = gtk_button_new_with_label("Optimisation CMF descendante");

  M4 = gtk_button_new_with_label("Quiter");

  gtk_box_pack_start(GTK_BOX(vbox), M1, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), M2, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), M3, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), M4, TRUE, TRUE, 0);

  g_signal_connect (G_OBJECT (M1), "clicked", G_CALLBACK (helloWorld), (gpointer) win);



  g_signal_connect(G_OBJECT(M4), "clicked",G_CALLBACK(show_question), (gpointer) win);



 gtk_widget_show_all (win);
  gtk_main ();
  return 0;
}










j'aime b1 ay niveau du void modification lorsque j'appui sur confirmer les données seront modifiée dans le fichier text et au niveau du void suppression lorsque j'appui sur supprimer le code la tailee et le poids seront supprimées de la fichier text fpersonne.txt
et meeerccciii
0