Re: Problem with GtkCList, dynamically creating with N columns...



Hi,

"J. Ali Harlow" <gtk-list avrc city ac uk> writes:

> That should be blankrow = (char **) malloc(vpsql->cols * sizeof(*blankrow));

Or glib-ish:

  blankrow = g_new ((gchar *), vpsql->cols);

But remember to use g_free() to free the memory g_new() allocates
for you.

> > for (ctr=0; ctr<vpsql->cols; ctr++)
> > {
> >   (char *)blankrow[ctr] = (char *)malloc(2);
> >   sprintf((char *)blankrow[ctr]," ");
> 
> These two lines could be blankrow[ctr] = strdup("")

or:

  for (ctr = 0; ctr < vpsql->cols; ctr++)
    blankrow[ctr] = "";

since it shouldn't hurt to use the same constant empty string 
everywhere. In that case you should of course not try to free 
it later.


Salut, Sven




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