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



On Fri, 26 Nov 1999, Aaron Walker wrote:

>ok, this should be relatively simple...
>but it is not working as I thought it would.
>
>I would like to open a file, read in each line, and make a clist row for
>each line
>here is what I have:
>
>...
>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);

(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



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