--- Jeremy Hill <[EMAIL PROTECTED]> wrote:
> Greetings and salutations,
>   First time posting; have a quick question for you. I use Erwin's note
> board system.  I was going to make a note formatter
> for it, but then I noticed that OLC had a formatter built in, called
> format_string:
> char *format_string (char *oldstring)
> 
> I figured I could kind of make use of this and use that instead of making my
> own line formatter, so this is what I did in
> void handle_con_note_finish (part of board.c):
> 
> case 'o': /*format note*/
>     ch->pcdata->in_progress->text = format_string
> (ch->pcdata->in_progress->text);
>     write_to_buffer (d,"Note formatted.\n\r",0);
>     break;
> 
> Now, here's my question-- some of the other calls to format_string use
> pointers, like
> *ch->desc->pString = format_string (*ch->desc->pString);
> while others do not, like
> pRoom->description = format_string (pRoom->description);
> 
> I was wondering if I am making a _TERRIBLE_ mistake by somehow sending
> non-pointed type stuff to format_string,
> which uses pointers.  (As you can obviously tell, I'm not exactly the
> world's most competent C programmer, verily).
> 
> Is passing the note text like that fine?  No bad juju with memory being
> scrambled or anything?  I tried it out with much suspense,
> and it appears to be okay--no compiler warnings on the make, and the box
> we're on still seems stable after making a few notes.
> (Obviously you can tell pointers to me are something similar to
> superstition).

Yes, they are a source of confusion for many newbie c programmers.. In answer
to your question yes, it should be fine. The source of your confusion lies in
the fact that you think 

pRoom->description = format_string (pRoom->description);

Is not passing a pointer into the function. It is. If you look up the
definition of room_index_data you will see that description is defined as:

char *description;

Thus it is a pointer to a character. So now you are thinking.. well if it is a
pointer, why doesn't it have the * symbol in front of it like:

*ch->desc->pString = format_string (*ch->desc->pString);

The question should be, why does ch->desc->pString need to be dereferenced with
the * before it gets passed. And the answer is because ch->desc->pString is not
a pointer to a character like pRoom->description. It is most likely defined in
descriptor_data as:

char **pString;

Or a pointer to a pointer to a character. Thus to get the character pointer
that pString points to you need to dereference it with the * operator.

I realize it's late, and this may not make the most sense of anything you've
read before, so if you have more questions feel free to ask.

~Kender


=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++:+ a-- C+++$>++++ UBLS++++$ 
P+++(--)$ L++>+++ E--- W+>++$ N !o K? w(--) !O 
M- !V PS+ PE(++) Y+ PGP->+ t- 5 X+() R(+) tv+@ 
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

Reply via email to