|
-
Dec 23rd, 2002, 06:58 PM
#4
Why the -1 jim? Isn't it confusing if your function uses a 1-based index?
And for the sake of good style the source should be const char*.
The code is quite simple.
The arguments are:
dest: the destination. A char buffer at least 2 chars long.
src: the source string.
where: the 1-based index into src of the character to copy.
*dest=*(src + (where -1) );
*dest
dest is dereferenced. This means the assign operation assigns to the character dest points at, not the pointer itself. It is equivalent to
dest[0]
*(src + (where -1) )
This is equivalent to
arc[where-1]
The -1 is because where is 1-based but arrays in C are 0-based.
So this takes the whereth character of src and copies it to the first position in dest.
*(dest+1)=0x00;
This adds a terminating NUL-character to dest in order to make it a valid C-string.
*(dest+1)
is equivalent to
dest[1]
so it accesses the second position of the buffer (the first is where the copied character is).
return;
This line is redundant in ANSI C but probably required by some of the weird compilers jim has or had to work with.
Last edited by CornedBee; Dec 23rd, 2002 at 07:01 PM.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|