gtk_clist problem

Well, I have problem with this function:
gtk_clist_append(GtkCList *clist, gchar *text[]);

I have a function that open a file and read some data from the file. The following code read data from the file.

gchar *host[ARRAY_SIZE], *temp;
/* ARRAY_SIZE is define in header file */
.
.
while(!feof(fp)){
i++;
fscanf(fp, "%s", temp);
host[i] = g_strdup(temp);
g_free(temp);
}
.
.
Is there any problem with this part of coding?
This function will return the number of line read from the file. Then I need to put all the data into a Clist. So I use a for loop to do it, like the following:

gint i, ctr;
/* ctr will hold the returned value from the above function */

GtkWidget *winNew = create_winMain_new();
GtkWidget *list = lookup_widget(winNew,"winMain_new_hostlist");
.
.
for(i=0;i<ctr;i++){
gtk_clist_append(GTK_CLIST(list), &host[i]);
}

Well, when I run this program, I get a segmentation fault and the program terminated.

However, I try to define host[] = {“s1”, “s2”, “s3”, “s4”, “s5”, “s6”, “s7”};

gtk_clist_append(GTK_CLIST(list), &host[i]) will work.

There is one more thing I’m not understand, as I refer to gtk manual and tutorial, the gtk_clist_append should work like this (host[i] without “&”):

gtk_clist_append(GTK_CLIST(list), host[i])

but this won’t work when I tried, can anyone explain it?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories