Thanx for your responses,
first I don't claim to be a good speller :)
next, I don't know what the size of the Title or descriptions will be, they
will change.
second, I am using this on a palm.
third, 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), 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)


----- Original Message -----
From: "James" <[EMAIL PROTECTED]>
Newsgroups: palm-dev-forum
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Saturday, May 25, 2002 8:03 PM
Subject: Re: passing char* data[10] question Code sample


> "bill" <[EMAIL PROTECTED]> wrote in message
> news:87230@palm-dev-forum...
> >
> > void Seperator (char* Data[], char* text)
> >  {
> >  UInt16 index=0, letterCount=0, row=0;
> >  char tempData[255];
> >  for (int i=0; i<strlen(text); i++)
> >   if (text[i]==' ')
> >    {
> >    tempData[letterCount]='\0';
> >    Data[row++]=tempData;
> >    letterCount=0;
> >    }
> >   else
> >    tempData[letterCount++]=text[i];
> >  }
>
> There are two major problems (not including the fact that "Seperator"
should
> be spelled "Separator"):
>
> 1. tempData is a local variable, and that means it's temporary.  When you
> set Data[row] = tempData, Data[row] points to the array (it does NOT copy
> the array), and when the Seperator function exits, that array is garbage.
>
> 2. Because Data[row] = tempData does not copy the contents of tempData, at
> the end of the loop, Data[0], Data[1], Data[2], etc. all point to the same
> thing in memory: tempData.
>
> You also have potential problems about overflowing the tempData and Data
> arrays, and unless your Titles and Description strings are set only at
> compile-time, it's something you need to pay attention to. (And if your
> Titles and Description strings are set only at compile-time, why bother
with
> the Seperator function at all?  Why not separate the strings in the first
> place:
>
> Char* Title[] = { "book1", "book2", "book3" };
> Char* Desc[] = { "fact1", "fact2", "fact3" };
>
> ?)
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
>



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to