Re: [gtk-list] erratum adding rows to CList from file



thanks! it works :-) I was wondering why it was segfaulting when I cast line
to gpointer :-)  Although, it seemed kinda awckward doing.

thanks again,
Aaron

Martin Kestel wrote:

> oops, sorry! switched in the lines... leave the gpointer casting out:
> here is the corrected version
>
> >>FILE *fp
> >>char line[256];
> >>if((fp = fopen("/tmp/output", "r")) == NULL)
> >>{
> >>    perror("/tmp/output");
> >>    exit(1);
> >>}
> >>clist = gtk_clist_new_with_titles(1, titles);
> >>gtk_signal_connect(GTK_OBJECT(clist), "select_row",
> >>            GTK_SIGNAL_FUNC(clist_selection_made_cb), NULL);
> >>gtk_clist_set_shadow_type (GTK_CLIST(clist), GTK_SHADOW_OUT);
> >>gtk_box_pack_start(GTK_BOX(vbox), clist, TRUE, TRUE, 0);
> >>gtk_widget_show(clist);
> >>while((fgets(line, sizeof line, fp)) != NULL)
> >>    gtk_clist_append(GTK_CLIST(clist), line);
> >>...
> >>
> >>ok, the above code yields the gcc error:
> >>passing arg 2 of 'gtk_clist_append' from incompatiple pointer type
> >>
> >>now I know that arg 2 needs to be a gchar *[], but even if I cast line
> >>to gchar *, it still doesn't work.
> >>
> >>Any ideas?
> >
> What if you add some
> char *pointer_to_entry;
>
> and then say
> pointer_to_entry = (gchar *)malloc((int)strlen(line));
> pointer_to_entry = (gchar *)&line;
>
> then appending should work:
> gtk_clist_append(GTK_CLIST(clist), (gpointer) pointer_to_entry);
>
> gtk_clist_append(GTK_CLIST(clist), &pointer_to_entry);
>
> (adding simply the '&' does not help the gcc...)
>
> This works for me like that, but the interesting question (to the
> chefs) is why it does not go the easy way you had tried at first?
>
>  Martin
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null

--
Visit my web site at http://iconmedia.com/cgi-bin/index.pl

Current uptime:
  8:30pm  up  1:22,  1 user,  load average: 1.96, 1.39, 1.19





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