|
-
Sep 25th, 2002, 04:56 AM
#5
You fill the provided array:
Code:
int charstararray2stringarray(int bufsize, string *buffer, int args, char * argv[])
{
int count = min(args, bufsize);
for (unsigned int i = 0; i < count; ++i)
{
buffer[i] = argv[i];
}
return count;
}
Some things:
a) in loops that traverse an array from start to end, it's always
for(loopvar = 0; loopvar < arlength, ++loopvar)
or loopvar++, doesn't really matter on a good compiler.
If you use loopvar <= arlength then there will be one iteration where loopvar == arlength. Since C/C++ arrays start indexing at 0, arlength is not a valid index anymore.
b) You don't do (string)"text" to convert a char array to string. This is the old C-style cast and not to be used. Instead you either explicitly call the contructor: string("text") or in this case take advantage of the fact that the = operator is overloaded to take char*:
string s = "text";
This avoid creating a temporary string object and is therefore faster.
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
|