![]() |
#1 |
New Member
Join Date: Apr 2002
Posts: 11
![]() |
![]() Let me start by saying I'm as green as they get, so bear with me. I'm also not familiar with this type of forum, so I hope this posts correctly...
This _seems_ simple enough, but I'm running into errors. The long and short of it is this: I want to take what a character puts in and store it in a structure, along these lines: [code] struct form { char * input[MAX_STRING_LENGTH]; }; struct form structure { '\0' }; for( i=0; structire.input[i] != '\0'; i++ ) {} /* If there's something there, skip it! */ structure.input[i] = argument; /* After we found a blank spot, store the input. */ [/quote] I want the user to be able to "store say haha!", "store say You're under my power!", "store say Foolish mortal!", then be able to execute all three says with one command. It stores the first one fine, but when I try to store a second command, it changes the first to what I want the second to be, and adds that second. When I store a third command, all three become that last command. The above example would store "say Foolish mortal!" three times. First thing that came to my mind is that there had to be a problem with my for statement, but a bit of elementary debugging seems to prove it works fine. I then recalled (and verified) that every instance of an array in my book (a poor one, I'm told) only has single characters. Can 'structure.input[0] = say hahaha!'? Can/Must I use a multi-dimentional array to store strings? That last didn't seem to work for me... Hope it was clear and concise. Thanks. |
![]() |
![]() |
![]() |
#2 |
Senior Member
|
![]() Yes you must have a multidimensional array to handle this sort of thing. But I'm guessing that you're not properly handling this array, and that's what's causing your problems. Here's an implementation that should work. A note of warning though, it's untested =)
[code] /* on the character structure */ char **storage; int storage_size; /* on character initialization */ character->storage_size = 0; /* in your storage command */ int i; char **new_storage; ++character->storage_size; new_storage = malloc(sizeof(char **) * character->storage_size); for (i = 0; i < character->storage_size - 1; ++i) new_storage[i] = character->storage[i]; free(character->storage); new_storage[character->storage_size - 1] = strdup(new_thing_to_store); character->storage = new_storage; /* on character deletion */ int i; for (i = 0; i < character->storage_size; ++i) free(character->storage[i]); free(character->storage);[/quote] It would be wisest to make those into seperate functions that operate on the storage array and size, but that should give you an idea of how to do it. |
![]() |
![]() |
![]() |
#3 |
New Member
Join Date: Apr 2002
Posts: 11
![]() |
![]() |
![]() |
![]() |
![]() |
#4 |
Member
|
|
![]() |
![]() |
![]() |
#5 |
Senior Member
|
![]() No he doesn't =P. str_dup() is a Diku function. strdup() is a BSD function, and I free it with free().
|
![]() |
![]() |
![]() |
#6 |
Senior Member
|
On the other hand, you could tell players to get a decent client with scripting functions, then give them a good VB/J/Javascript site with tutorials.
|
![]() |
![]() |
![]() |
#7 |
Member
|
|
![]() |
![]() |
![]() |
#8 |
New Member
Join Date: Apr 2002
Posts: 11
![]() |
Heh, won't quite fit what I'm working towards, Seth. Previous examples were used to (hopefully) keep things simple.
Thanks again, Yui. And thanks, Koryon. Doesn't completely make sense, but when I need to learn it, it'll likely make it a bit easier. |
![]() |
![]() |
![]() |
#9 |
Member
Join Date: May 2002
Posts: 68
![]() |
You could handle this with a double/single linked list too, but that's just the crack in my veins talking.
|
![]() |
![]() |
![]() |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
newbie | crownrahul | Tavern of the Blue Hand | 1 | 02-04-2006 10:12 AM |
Okay, this really is a newbie q. | Rindu | Newbie Help | 1 | 12-24-2005 11:56 AM |
Newbie Welcome... | ozental | Introduce Yourself | 0 | 12-03-2004 11:27 AM |
Newbie Looking for His Second MUD | Walkingman | Newbie Help | 3 | 11-18-2003 01:30 PM |
Newbie Demo | Tavish | Advanced MUD Concepts | 9 | 04-28-2002 01:53 AM |
|
|