"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/

Reply via email to