GList and combobox problem



Hi all.
I have the following problem. 
I want to fill a GList *list with the names of files stored in a
directory and then use this list together with a combobox. So, I expect
to see the files' names as popdown strings, but all I get is some
garbage. A part of the code follows:

/* function I use to initialize the list with files' names */
GList *init_list(GList **list, char *directory)
{
 DIR *dp;
 struct dirent *de;

 dp = opendir(directory);
  while((de = readdir(dp)) != NULL)
  {
   *list = g_list_append(*list, de->d_name);
  }
 
  closedir(dp);
  return(*list);
}


/* this is in main() */
 GList *list;
 GtkWidget *combo;  
 int i;

 list = NULL;
 list = init_list(&list, "/home/user/dir");
 /* this correctly outputs files' names */
 for(i = 0; i < g_list_length(list); i++) 
  printf("DEBUG: list's element number %d is %s\n", i, g_list_nth(list,
i)->data);

 gtk_combo_set_popdown_strings(GTK_COMBO(combo), list);
 gtk_widget_show(combo);

I searched more info in the tutorial and the reference, but I couldn't
find a solution. Any help is much appreciated,
thanks,
Marco.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]