Re: appending a clist row



learfox furry ao net wrote:

[..]

One thing you can do is creating a blank array:

gint i, clist_columns = 4;
gchar **text;

/* Allocate a blank array of strings. */
text = (char **)malloc(clist_columns * sizeof(char *));
if(text != NULL)
{
        /* Set each pointer to point to an allocated empty string. */
        for(i = 0; i < clist_columns; i++)
                text[i] = strdup("");
}

just for my curiosity: why do you use strdup() instead of passing the
const char * "" ?

/* Add the item into the clist. */
gtk_clist_append(clist, text);

/* Now deallocate text. */
if(text != NULL)
{
        for(i = 0; i < clist_columns; i++)
                free(text[i]);
}
free(text);
text = NULL;
clist_columns = 0;

this would not be necerssery, if you wouldn't have used strdup().

regards ...
clemens




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