I'm following the instructions of the official Raspberry Pi book called An introduction to C & GUI Programming (link).
It uses GTK2 to create a gui in C.
I encountered some problems trying the code that should save a file. Here the code of the book (same I used):
#include <gtk/gtk.h> static void save_file (GtkWidget *btn, gpointer ptr) { GtkWidget *sch = gtk_file_chooser_dialog_new ("Save file", GTK_WINDOW (ptr), GTK_FILE_CHOOSER_ACTION_SAVE, "Cancel", 0, "OK", 1, NULL); if (gtk_dialog_run (GTK_DIALOG (sch)) == 1) { printf ("%s selected\n", gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (sch))); } gtk_widget_destroy (sch); } void end_program (GtkWidget *wid, gpointer ptr) { gtk_main_quit (); } int main (int argc, char * argv[]) { gtk_init (&argc, &argv); GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL); GtkWidget *btn = gtk_button_new_with_label ("Close window"); g_signal_connect (btn, "clicked", G_CALLBACK (end_program), NULL); g_signal_connect (win, "delete_event", G_CALLBACK (end_program), NULL); GtkWidget *vbox = gtk_vbox_new (FALSE, 5); gtk_container_add (GTK_CONTAINER (win), box); GtkWidget *fc_btn = gtk_button_new_with_label ("Save file"); g_signal_connect (fc_btn, "clicked", G_CALLBACK (save_file), win); gtk_box_pack_start (GTK_BOX (vbox), fc_btn, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), btn, TRUE, TRUE, 0); gtk_widget_show_all (win); gtk_main (); return 0; } The books says that this program should open a window with a button that, if clicked, opens a new window where I can insert the name of the file and with OK I should be able to save it.
The resulting file path is printed correctly inside the terminal.
If I enter inside the path where I saved the file, the file doesn't exist! It's not hidded neither saved with a different name.
Is there something missing in this piece of code?