I think I have gotten that part down thanks.
How I would un append that list.
---------- Post updated at 01:30 PM ---------- Previous update was at 01:22 PM ----------
I mean will the code below work if descr_list is a global variable? ---------- Post updated at 01:32 PM ---------- Previous update was at 01:30 PM ----------
I'm iffy on wether that will work or not because I thought pointers work differently.
Meaning I am worried that if r = l; and then l = l->next, then r will be pointing to
l->next and I will be freeing l->next when I free r.
---------- Post updated at 01:34 PM ---------- Previous update was at 01:32 PM ----------
also thanks again you've been very helpful. I have more questions to ask but I wont
ask untill I get to them.
Forget everything you know about pointers. They have no abilities to change themselves.
addr2=addr1 does nothing at all to the contents of the array -- would you agree?
This will print 10, would you agree?
Pointers are just index numbers for the huge array of memory that belongs to your process. Copying them and moving them around does absolutely nothing to the contents.
Which means, this code is equivalent:
You're getting much closer, but what happens to the descr pointing to the node you freed? It's just a number -- it doesn't change by itself just because you made a library call.
So it's still sitting there pointing to the memory you just freed. That will crash or do weird things next time you read it.
Which means you have to stop one early, so you can free the next node and tell the current node where the list ends.
Last edited by Corona688; 09-29-2011 at 05:05 PM..
---------- Post updated at 03:52 AM ---------- Previous update was at 03:48 AM ----------
Does this loop through the entire descr_list?
while(descr_list->state == 0)
And why did you do this part?
while(l->next != NULL)
I feel like I'm missing something. Like cause I can't see the reason for looping
through l->next.
---------- Post updated at 03:53 AM ---------- Previous update was at 03:52 AM ----------
I'm just wondering if you did that second part just in case I want l to be iterated
through but I gotta make sure.
---------- Post updated at 05:57 AM ---------- Previous update was at 03:53 AM ----------
Ok help me with this part and I'll prolly understand the readjust_descr
function better. Ok the variables of the function here are the socket
that I will send messages to and a structure defined right before this
function is used. descr_list is a global structure descr structure posted
above the function in the code below. Ok the function works. It makes
the structure defined before it, equal to a Null part of a copy of descr_list.
My problem is the fact that I want descr_list to have struct descr *p as
a part of itself and I thought initializing a null part of d would do that but
now I am thinking that it wont.
Ok so heres a huntch I have at making the structure descr *d part of
descr_list. Maybe I just change the value adescr_list untill it is pointing to
a NULL structure and then make it equal to d. I thought maybe I'll do that at the end of initialize_descr. I'm thinking though about the descr_list
structure and if it will still point to the beginning of the list if I access it in a different function.
What do I have to add to this function to make a list of player structures out of the global variable descr_list?
something like while descr_list->next != NULL descr_list= descr_list->next descr_list ->next = p. I am thinking that
that might not wrk because descr_list will now point to the structure before p and not at the very first structure
of itself.
---------- Post updated at 06:08 AM ---------- Previous update was at 05:57 AM ----------
I just don't understand.
---------- Post updated at 06:20 AM ---------- Previous update was at 06:08 AM ----------
I think I figured out a way to do this. I'll just add another structure to every
structure created by that thing that points to the first part of itself. I'm gonna post
the finished function when I'm done with it. Maybe you could look at it. ---------- Post updated at 06:56 AM ---------- Previous update was at 06:20 AM ----------
So what do you think?
Will she work?
I think I have finally done it.
---------- Post updated at 07:28 AM ---------- Previous update was at 06:56 AM ----------
Also will this work?
Last edited by Errigour; 09-30-2011 at 08:31 AM..
Reason: I'm trying to explain what I'm doing in words.
I explained absolutely everything in my code comments and suggest you read them.
Quote:
while(l->next != NULL)
I feel like I'm missing something. Like cause I can't see the reason for looping
through l->next.
If you delete the current node, the previous node is left pointing to invalid memory.
when you call free() on memory block 2, what happens to memory block 1? Absolutely nothing. It still points to memory block 2. It doesn't know it's the last node in the list! Next time you use the list it'll try to access block 2 anyway, and either crash or do strange things.
Whenever you're not at the first node in the list, you need to check and free the next node, not the current one, otherwise you'll leave dangling pointers all over the place.
Quote:
I'm just wondering if you did that second part just in case I want l to be iterated
through but I gotta make sure.
I explained exactly why I did absolutely everything in the comments I put in my code, I suggest you read them. If you don't understand my comments, ask questions about them, please don't just ignore them.
Quote:
My problem is the fact that I want descr_list to have struct descr *p as
a part of itself and I thought initializing a null part of d would do that but
now I am thinking that it wont.
If I get your meaning, it won't.
A pointer is a memory address and nothing more. Trying to initialize a NULL means trying to write to address 0 in memory, which crashes.
Since you never actually posted your data structures, I certainly can't show you how to fix them.
Quote:
Ok so heres a huntch I have at making the structure descr *d part of
descr_list. Maybe I just change the value adescr_list untill it is pointing to
a NULL structure and then make it equal to d.
Changing the pointers doesn't change the memory. Please read the examples I posted for you about array indexes.
How about:
Quote:
What do I have to add to this function to make a list of player structures out of the global variable descr_list?
something like while descr_list->next != NULL descr_list= descr_list->next descr_list ->next = p.
There's only two times you'd change the value of descr_list.
1) When the list is empty. descr_list must be set to the new first node.
2) When the first node is being deleted. descr_list must be set to the next node.
If you need to add a 'self' pointer to keep your code together, you must be doing something very strange indeed.
---------- Post updated at 06:56 AM ---------- Previous update was at 06:20 AM ----------
So what do you think?
Will she work?
I think I have finally done it.[/quote] For yog's sake. If you've posted 5 times while I'm asleep, posting a 6th won't make me wake up.
I can't tell if your code works or not since you changed the structures again and didn't post what it now is, but it looks like you've added 3 or 4 useless pointers which are only helpful for working around bugs in your code.
[/QUOTE] It will not work, for all the reasons I gave you in my last post, which I really, really, really wish you'd read.
---------- Post updated at 11:43 AM ---------- Previous update was at 11:09 AM ----------
And you're still forgetting all your return 1's! The return 0's and error checking are useless if you don't return success when you actually have success!
Here's working code for a linked list.
Last edited by Corona688; 09-30-2011 at 02:56 PM..
I didn't spam so you would answer faster I just kept updating my post so
you would see that stuff before you replied. Stuff just hit me while I tried
to make this stuff work.
Anyways I have been using all the stuff you talked about. Could you just
look at my last modification of initialize descriptor and see if it will cause
errors or not.
I know that struct descr **p changes to what I want it to be
but I just wanted to know what you thought about making a linked
list of all the descriptors. I'm worried about the lines under the text // I think I'm updating my descr_list after this line */
You should not keep the head pointer inside the list, no. You'll still need another head pointer to point to the head pointer -- how else will your program find it? Which makes it a bit redundant.
Hi Guys,
I have a list a hotels stored in many different text files.
This list is kept in the following format:
20/03
Hotel:
The Bear Hotel
Honey Street
Woodstock
UK
Tel:+44-xxxxxx
Rate: 100
21/03
Hotel:
The Bush Hotel
Nice Street
Farnham (4 Replies)
Hello,
Please suggest me the ways how to get graphical interface on AIX server.I need to create oracle database for which I need graphical access.
Best regards,
Vishal (4 Replies)
Hi all,
I new to scripting and i need to know how to put the script when the capture goes down in the feeds database.. I tried with this "ps -ef | grep asn" command and it displaying the capture,apply time. But the alert we are receving now is replication is failed . So i need to develop the... (1 Reply)
#!/bin/bash
user=`mysql userList -uuserlist -puserlistpassword -s -N -e "SELECT userName FROM users WHERE activated='n'"`
for i in $user; do
useradd "$i" -m
doneThis is what I have done so far. But obviously it still does not work.
I'm trying to create users based on information stored in a... (5 Replies)
Hello ,
I am new in this forum and need your help as I am totally confused :confused:
I read a lot of threads and tried to search a lot but did not get the exact answer to my question.
I just want a simple (content wise may be long) shell script to create oracle database.
In detail:... (5 Replies)
Hi.
I have two text files(tables) which include some information and I want to make some query codes using them.
First of all, I want to create bash script that read this two tables, create/open database and insert data from files into database.
#!/bin/bash
while read line; do
... (1 Reply)
Hi,
I have backup file of database in my server. I want to create a that database in the same Mysql Server. How can I do that?
Please send the steps to create the database using backup file?
Thanks a lot, (1 Reply)
I installed Oracle 10 software on Solaris 11 Express, everything was fine execpt I can't create database using dbca.rsp file. I populated file with following options.
OPERATION_TYPE = "createDatabase"
GDBNAME = "solaris_user.domain.com"
SID = "solaris_user"
TEMPLATENAME = "General... (0 Replies)
:cool: I like Vibhory2 like the idea of tapping into the kernel.. although not as indepth as he/she... i want to create a virtual databse of a few ma chines with connectivity and defiinte knowledge to create it.. I havebeen working on the project for a year now.. ! before unix (1 year exactly) i... (20 Replies)