[Fwd: Need Help using GLib -> GList]

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

 



Pardon my double post. I was not subscribed on the first and it is awaiting moderator. So I subscribed and sent again. See below.

-------- Original Message --------
Subject: Need Help using GLib -> GList
Date: Sun, 03 Apr 2005 17:49:05 -0700
From: Jerry DeLisle <jvdelisle@xxxxxxxxxxx>
To: gtk-list@xxxxxxxxx

I am trying make a list of lists.  When I scan through this list of
lists using g_list_first() and g_list_next() it passes through the list
one time fine, then after that it does no more.  Here is a snippet:

GList * init_players(GList * thePlayers, int num){
    int i;
    GList * ahand;
    for (i=0;i<num;++i){
	ahand = g_new(GList, 1);
	ahand->data=NULL;
	thePlayers=g_list_append(thePlayers,ahand);
    }
    return(thePlayers);
}

void deal(GList * adeck, GList * theplayers){
    int count = 0;

    adeck=g_list_first(adeck);
    while (adeck != NULL){
	g_print("Outer loop %d.\n",++count);
	theplayers=g_list_first(theplayers);
	while(theplayers != NULL){
	    g_print("The player is %u.\n",theplayers);
	    g_print("Inner loop.\n");
	    theplayers=g_list_next(theplayers);
	}
	adeck=g_list_next(adeck);
    }
    g_print("%d cards were dealt.\n", count);
}

In a nutshell I am simulating dealing a deck of cards to num players.
The first pass through the inner while loop shows 'reasonable' pointer
values for theplayers list.  The second pass through, theplayers = NULL.
 The call to g_list_first is returning NULL for ever so the list seem
to be lost.  I am not appending anything to the list yet, I was just
trying to see if I can scan through the players list correctly.  When I
call this with num =4 I get four passes in the inner loop, after that it
doesn't work.

Can anyone give me some hints?

Jerry

_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux