|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
Okay, I've been hammering away at this for more time than I care to admit. What this program is supposed to do is create a linked list of random numbers, print them out, and find the smallest one. I haven't been able to successfully code the function that finds the smallest number. I suspect it is something with the pointers in that function.
If anyone could please tell me where the heck I'm going wrong, I'd greatly appreciate it.
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
Last edited by Force Flow; 12-14-2003 at 11:50 PM. |
|
|
|
|
|
#2 |
|
Member (8 bit)
Join Date: Dec 2003
Posts: 130
|
struct_prog.exe - 1 error(s), 0 warning(s)
EDIT: I think its a bug that wont let the code execute properly... Last edited by monster; 12-14-2003 at 07:42 PM. |
|
|
|
|
|
#3 |
|
Member (7 bit)
Join Date: Sep 2003
Posts: 90
|
normally, i charge for this kind of work, but i'll let you off easy this time.
included is my code. i stress, MY code. i entrust you to learn from it, not to steal it. it bears some semblance to the original, but fixes many of the little things. so, please look over it and ask me questions. i removed the JUMP typedef. it only confused me. i deal better if i explicitly know something is a pointer. there were many unused variables. gcc on any level should warn you of these. i assume you are using some form of gcc? the srandom function sets the seed for the random generator based on the current time, so it should change everytime you run it. i always insert at front because it is easy and constant time. you forget in many places to check for a NULL pointer on head. if the list is NULL your code will barf. the specific problem (or at least one) was the assignment of p to value. p is a pointer, value is an int. gcc warns about this implicit casting also. also, free the memory!!!! if you have access to purify, then run it. it has saved me more than once. please respond with questions so i at least know you looked at it. AS Attachment removed by moderator by request due to it containing personal information Last edited by glc; 12-15-2003 at 09:06 PM. |
|
|
|
|
|
#4 |
|
Member (7 bit)
Join Date: Sep 2003
Posts: 90
|
oh, i forgot to mention, the code runs without warnings using gcc with the following tags:
gcc -Wall -O2 -Wall turns on all warnings and is ALWAYS a good idea -O2 turns on cool optimizations AS |
|
|
|
|
|
#5 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
Thanks, AerynSedai. That worked out.
![]() btw, the random seed is strand()
|
|
|
|
|
|
#6 |
|
Member (7 bit)
Join Date: Sep 2003
Posts: 90
|
are you using standard C libraries?
i used rand and srand which are in stdlib.h, but i can't find a man page for "strand" AS |
|
|
|
|
|
#7 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
whoops, my mistake. It is srand.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|