You need to allocate storage to hold the strings pointed at by the 2nd
parm to g_list_append().  The glist isn't responsible for allocating
fresh string space to hold the various strings pointed at by that 2nd
parm, so if you keep using the same pointer in calls to g_list_append(),
and at the end all those same pointers point to 'Zack', that's what you
should expect to see in the list.


  // Wally

On Thu, 2006-04-27 at 19:24 +0200, [EMAIL PROTECTED] wrote:
> Hi,
> 
> I'm pretty frustrated because I can't solve this by myself. Can you help
> me?
> 
> I have a file that looks like
> 
> 1 Adam
> 1 Bert
> 1 Daniel
> 2 Marc
> 2 Sam
> ..
> ..
> 9 Zack
> 
> and so on. That's an int number, a blank and a name. My code looks like this 
> snip ...
> GList *glist = NULL;
> FILE *fp;
> if ( ! ( fp = fopen(filename, "r")))
> {
>       fprintf(stderr, "Errror in opening data file %s: error: %s\n", 
> filename, strerror(errno));
> }
> else
> {
>       while (fscanf(fp, "%i %s", f_i, f_c) != EOF)
>       {
>               if ( f_i == 1 )
>               {
>                       fprintf(stderr, "f_i: %i;\tadding: %s\n", f_i, f_c);
>                       /* everything correct up to here */
>                       glist = g_list_append(glist, f_c);
>               }
>       }
>       fclose(fp);
> }
> gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
> g_list_free(glist);
> 
> 
> The output from the fprintf is absolutely correct. In the combo I have
> the correct number of entries but all of them are 'Zack'. What's wrong
> with my code? I had a look at this for several hours and I googled a
> long time but I don't find it.
> 
> Please help me. I really appreciate your help.
> Thank you in advance
> Regards
> 
-- 
Your eyes are weary from staring at the CRT.  You feel sleepy.  Notice
how restful it is to watch the cursor blink.  Close your eyes.  The   
opinions stated above are yours.  You cannot imagine why you ever felt
otherwise.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to