Re: Problem with linked lists and CLists



Hi,

On Thu, 2002-07-25 at 23:53, Szymon Bąkowski wrote:
> Hello everyone :)
> I`m jus started writting in GTK+ 1.2 and I stuck in two points:
> first I was trying tu put something from two dimensional array to CList but
> I get again and again error but not during compilation but during program
> run.

What error are you getting at runtime?  The code looks ok (though I
didn't actually try it).

[snip]

> My second question is about double linked list in gtk. I created something
> like this:
> 
> 
> char numerr[]={"123"};
> struct komp
> {
>     char *numer;
>     char *ip;
>     char *stan;
> };
> struct komp *elementy;
> elementy=malloc(sizeof(struct komp));
> strcpy(elementy->numer,numerr);
> list_ko=g_list_append(list_ko,(gpointer)elementy);
> printf("%s\n",(char*)list_ko->elementy->numer);
> 
> and maybe stupid question I don`t knw how to get tu the "numer" element of
> this

A doubly-linked list is composed of nodes which have the following
structure:

struct GList
{
  gpointer data;
  GList *next;
  GList *prev;
};

So, to access your data you need to cast the "data" field or by using
the g_list_nth_data function.  Read the reference manual for more
information.

Gustavo





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