Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Programming in Linux _ Link List C Problem

Posted by: docmur Jun 27 2008, 07:26 PM

I'm working on this project on linux right now.

It involves the following parts:

1) A deck of cards
2) A hand of cards
3) Link Lists.

I've pastebined the code. Now the project uses linked lists, as I'm not a comp sci student I'm doing this for interest. I'm actually a comp eng student so my C background is only meant to be good for basic work. I do alot of assembler if that helps.

So here's how the program works, I make a list of cards (the deck), the numbers 2 - 14 appear 4 times so 2 - Ace , 4 times as to simulate a deck. Then I randomize a number using rand. rand is seeded by Time(NULL). The random value is between 2 - 14 and then the function ListSearch goes thought the deck and when it finds the value in the deck it assigns that value to the hand. Of course then I remove the node of the list that is matched so it can't be picked up again.

Here's what is actually happening. When my function finds the value it is in deed assigning it to the hand but it's remove (Random Number - 1) from the list and there for when you do the call multiple times to make the entire hand only a few cards are missing from the deck of it crashes.

Now I've gone though google and wiki and yet still don't know why this happening, can anyone help.







Powered by Invision Power Board (
© Invision Power Services (