Hi,
I am newbie to GTK and C
programming.Earlier i worked only on VB 6.0. So my question may be very silly
some times.Please co-opearte.
In the following code I am able to bind two
dimensional declared array to GtkClist Widget. But the problem arises
when i dynamically allocate memory for two dimensional array and try to
bind it gives error.
sql::SqlDatabase db("test.db",
true);
sql::SqlDatabase::iterator i; void on_button1_clicked (GtkButton *button, gpointer user_data) { GtkWidget *clist; const char** szData; int cnt = 0; clist = lookup_widget(GTK_WIDGET(button), "clist1"); //char *row_array[1][2]; char **row_matrix;
int j,k; bool check; sql::SqlDatabase::iterator i; row_matrix = (char **)malloc(size * sizeof(char)); //size IS FIXED 1 check=TRUE; for (i = db.begin("select * from PHI"); i != db.end(); ++i) { if(check==TRUE){ for (cnt=0;cnt<size;cnt++){ row_matrix[0]=(char *)malloc(i->count()*sizeof(char)); //i->count() gives number of columns in table } check=FALSE; } for (int j=0;j < i->count();j++){ szData =i->data(); //i->data() contains value sprintf(&row_matrix[0][j],"%s",szData[j]); // ABLE TO PUT THE VALUE IN ALLOCATED SPACE //row_matrix [0][j] = g_strdup_printf ("%s",(void *)szData[j]); //THIS WORKS FINE } gtk_clist_append ((GtkCList *)clist,(char **)row_matrix[0]);//GIVES ERROR UNREFRENCED MEMORY AND TERMINATE } |