At 8:32 PM -0700 5/25/02, bill wrote:
>Thanx for your responses,
>first I don't claim to be a good speller :)
>next, ...
>second, ...
>third, ...
Nor do you know how to count. :-)
>I have all the books, and then read the and read them, been at this
>one thing for a while, then I have read them again (as I mentioned),
If you have all the books, you might want to look at strtok(). It
seems to do what you want. But it would depend on your C library as
to whether or not it exists in your environment.
>but it seems that most of them have to do with known sizes, I don't
>know how many strings that title and description will have, all I
>will know is that they will have the same amount. I won't know the
>total until after the return from the 'Separator' function, because
>they have not been separated yet and I don't know the lengths of the
>strings until after that either. I guess, I need to know how to
>declare space for something before you know the size, or do I just
>pick a size that is larger than any that might occur?? I will
>re-read the posts you sent and try to get info out of them that I
>missed. Oh yes, Print just puts up an alert box with the output in
>it. (sorry)
You can get the size before you allocate your data.
In general, what you need is an array of arrays. The first array
contains pointers to the second arrays. The second arrays contains
the characters.
Something like the following may work (eschewing strtok, which may
not be around and which may not be worth the effort anyway):
MemHandle Separator (const char* str)
{
MemHandle result = NULL;
const char* strStart = str;
const char* strEnd = str;
while (*strEnd)
{
// Look for a delimiter.
if (*strEnd == ' ')
{
AddString (&result, strStart, strEnd);
++strEnd; // Skip the space.
}
++strEnd;
}
// Add the final sub-string between the last delimiter and the
// and of the input string.
AddString (&result, strStart, strEnd);
return result;
}
void AddString (MemHandle* h, const char* strStart, const char* strEnd)
{
size_t newStrSize = strEnd - strStart;
if (newStrSize == 0)
return;
size_t index = 0;
// Make the outer array big enough for the new string.
if (*h == NULL)
{
*h = MemHandleNew (sizeof (char*));
}
else
{
index = MemHandleSize(*h) / sizeof (char*);
*h = MemHandleResize (MemHandleSize(*h) + sizeof (char*));
}
// Copy the new string into it's own hadle.
MemHandle newStr = MemHandleNew (newStrSize + 1);
MemPtr newStrP = MemHandleLock (newStr);
memcpy (newStrP, strStart, newStrSize);
newStrP[newStrSize] = 0;
MemHandleUnlock (newStr);
// Add that handle to the containing array.
MemPtr p = MemHandleLock (*h);
((MemHandle*) p)[index] = newStr;
MemHandleUnlock (*h);
}
Please note that I just typed this in my e-mail program and compiled
it with my eyes (which are not ISO/ANSI compliant), so there may be
some bugs. But that's the general outline of what I'd do. (I'd also
do some error checking around the calls to MemHandeNew and
MemHandleResize.)
-- Keith
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/