How can I return in a GTK function in C a list of characters with GSList?

32 Views Asked by At

I need to save the path of each file contained in a folder. This is the code:

void on_file1_file_set(GtkFileChooserButton *chooser){
 GSList filelist;
 printf("file name = %s\n", gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(chooser)));
 printf("folder uri = %s\n", gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(chooser)));    
 printf("folder filenames = %s\n", gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(chooser)));
 return filelist;
}

and my error:

warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘GSList *’ {aka ‘struct _GSList *’} [-Wformat=]
1

There are 1 best solutions below

2
abinitio On

The error is telling you that you are passing the wrong type of argument into the string formatter. In your third printf() statement you are passing in the return value from gtk_file_chooser_get_filenames() which is of type GSList, not char.

All you need is to use the return value from that function. It is the GSList you are looking for.

void on_file1_file_set(GtkFileChooserButton *chooser){
 GSList *filelist;
 filelist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(chooser));
 return filelist;
}