Hey,
first thank you for your help.

There are some point i want to mention (to ask):

I terminate the strings with the '\0'-sign, this is correct!!!

What should i use instead of MemHandleNew() ? Perhaps malloc?
Or how would you solve this?

Thanks

"Jan Slodicka" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> Hello,
>
> Here are just a few points:
>
> - Do you really want string separators? If not, then the parameter token
> should be char. If yes, then you should compare all characters of the
> string. Or you want to support multiple separators? Then check them all.
(By
> the way, "token" means something else.)
>
> - How the caller will know how many strings are in the output array?
>
> - Take out the invariants out of the cycle. (StrLen)
>
> - Strings are terminated by 0. You don't take this into account.
>
> - Remarkable construction:
>     MemHandleLock (MemHandleNew (StrLen(extracted)))
>   a) inefficient
>   b) Are you sure you want blocks from the storage memory? And should they
> be locked?
>   c) What about if the allocation fails?
>
> - If you want a general solution, then you cannot rely on assumptions such
> as max. token size 255 or sufficient length of the output array.
>
> CW is not the fault - for sure.
> Also, it shouldn't be any problem to find ready-to-use tokenizers on the
> web.
>
> With best regards,
>     Jan Slodicka
>
>
>
> ----- Original Message -----
> From: "Pit" <[EMAIL PROTECTED]>
> Newsgroups: palm-dev-forum
> To: "Palm Developer Forum" <[EMAIL PROTECTED]>
> Sent: Thursday, April 08, 2004 12:18 PM
> Subject: char* [] and String-Tokenizing - Problem
>
>
> > Hi all,
> >
> > i am working on a function which separates a given string in multiple
> > substrings.
> >
> > Example:
> >     given is the following string:
> >     Char * temp = "sdlkfslkdj/gowrsdn/sfgmbdf�sdfg/sdfgfdglk";
> >
> >     i want then following:
> >     Char * temp1[] = {"sdlkfslkdj", "gowrsdn", "sfgmbdf�sdfg",
> "sdfgfdglk"};
> >
> > Therfore i wrote a function who should handle this!
> >
> > static void Tokenizer (char* input, char* token, char* returnV[]) {
> >         int i, j = 0, k = 0;
> >         char extracted[255];
> >
> >         for (i = 0; i <= StrLen(input); i++)
> >         {
> >              if (*token == input[i] || i == StrLen(input) )
> > // terminate if '/' found or end of string reached
> >              {
> >                   extracted[j] = '\0';
> > // terminate extracted String
> >                   returnV[k] = MemHandleLock (MemHandleNew (StrLen
> > (extracted)));         // Allocate memory for new String
> >                   StrNCopy (returnV[k], extracted, StrLen (extracted));
> > // Copy String into allocated memory
> >                   j = 0;
> > // skip to start of extracted-string
> >                   i++;
> > // skip '/'
> >                   k++;
> > // skip one position in returnV-Array
> >              }
> >              extracted[j] = input[i];
> >              j++;
> >         }
> > }
> >
> > i call this function with the following code:
> >
> >  char* test =
> > "1peterg/dewrrdfg3/wesjrhsdhf/ksdhfjk/eritjeklgjlsdkg";
> >  char* search ="/";
> >  char* temp[] = {NULL, NULL, NULL, NULL, NULL};
> >  Tokenizer (test, search, temp);
> >
> > after the call of Tokenizer, temp shows the following values:
> >
> > temp[] = {"sdlkfslkdj", "gowrsdn", "sfgmbdf�sdfg", "sdfgfdglk�" ��" �",
> > NULL};
> >
> > As you can see is the 4. value not correct, there seems to be some
memory
> > bullshit.
> > It occurs form times to times, and also with other bullshit.
> > Is this perhaps a problem of CW or am i doing somethins wron with the
> > memory-allocation?
> >
> > Thanks, for any suggestions
> > Best Regards
> > Peter
> >
> >
> >
> > --
> > 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