Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
> Link List C Problem
docmur
post Jun 27 2008, 07:26 PM
Post #1


I Eat C Code for Breakfast
****

Group: Members
Posts: 276
Joined: 9-November 04
From: Canada Ontario
Member No.: 4,136



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.

Thanks

Docmur


Pastebins:

MList.c
http://pastebin.com/m65ea8abe

MList.h
http://pastebin.com/m16fd1638

main.c
http://pastebin.com/m6bcbe671


--------------------
Gentoo ROCKS!!!!! Go and emerge the world
Go to the top of the page
 
+Quote Post

Posts in this topic
- docmur   Link List C Problem   Jun 27 2008, 07:26 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 17th October 2017 - 10:22 AM