Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ I was looking through the str's in db.c...
|
I was looking through the str's in db.c...
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Nick Cash
USA (626 posts) Bio
|
| Date
| Thu 06 Feb 2003 02:16 AM (UTC) |
| Message
| I was looking through the str functions (e.g. str_cmp, str_prefix, etc.) and I found str_dup. I've noticed it before in other files, so I was curious to see what it did. The comment before it offer's no explanation, unlike str_cmp, so I am still wonder. It may be a small code, but its used enough it my code to get me to ask. Can anyone explain to me the significance of str_dup?
Thanks. |
~Nick Cash
http://www.nick-cash.com | | Top |
|
| Posted by
| Nick Cash
USA (626 posts) Bio
|
| Date
| Reply #1 on Thu 06 Feb 2003 03:21 AM (UTC) |
| Message
| Also another thing, if you would be so kind to answer it for me. I'm writing a code that calls for the use of switch(). I was looking through some examples in other codes and I noticed that a lot of the use ch->dest_buf and ch->dest_buf2. What are these used for, I see them mostly in swskills.c, which is kind of making items, so it might have to do with that. Anyways, if one of you really smart and experienced coders could answer my newbie questions that would be great.
Thanks for everything. |
~Nick Cash
http://www.nick-cash.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #2 on Thu 06 Feb 2003 09:14 PM (UTC) |
| Message
| str_dup duplicates a string. C doesn't have really elegant string handling built in, so you normally represent strings by allocating memory (using malloc) and then copying the data into the allocated memory. You then refer to the string by a pointer to its allocated memory.
Thus, you can't just make a copy of a string by copying the pointer, as you would have two pointers pointing to the same piece of memory, and if you changed or deleted one, you would change or delete both.
str_dup allocates another batch of memory, and then copies the original string into it, thus duplicating the string.
As for ch->dest_buf2 it is hard to say without seeing the code, but sounds like a "destination buffer". |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
8,715 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top