#include #include // need this header for file operations #include static GtkWidget *entry; static void button_clicked (void) { FILE *outfile; char *text = gtk_entry_get_text (GTK_ENTRY (entry)); // open outfile in append mode outfile = fopen ("dumpfile.out", "a"); if (!outfile) g_error ("couldn't open file!"); // write text to file...add a newline manually if you need it fputs (text, outfile); // and close the file again fclose (outfile); } int main (int argc, char *argv[]) { GtkWidget *win; GtkWidget *vbox; GtkWidget *button; gtk_init (&argc, &argv); win = gtk_window_new (GTK_WINDOW_TOPLEVEL); vbox = gtk_vbox_new (TRUE, 0); gtk_container_add (GTK_CONTAINER (win), vbox); entry = gtk_entry_new (); gtk_box_pack_start_defaults (GTK_BOX (vbox), entry); button = gtk_button_new_with_label ("Save Text"); gtk_box_pack_start_defaults (GTK_BOX (vbox), button); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (button_clicked), NULL); gtk_widget_show_all (win); gtk_main (); return 0; }