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/