Hi,
i want  to store the following string, separated by '/' in to the pointer
temp!

char* test = "1/2/3/Peter/sdlk
fslkdj/gowrsdn/sfgmbdg,m.,.-f�sdfg/sdfgfdglk";
char** temp;

Therfore, i think i have to allocate memory!
char** temp, is a pointer to pointers to strings (char *), am i rigth?

So i allocated memory for temp and also for the entrys of temp (temp[0]).
Because i dont know how many string i store in temp, i count the '/' in the
test - string and allocate then the memory:
Is this correct?

char separator = '/';
int i,k = 0;
for (i = 0; i <= StrLen(test); i++) {
     if (separator == test[i])
      k++;
}
temp = MemPtrNew ((k+1) * 4);

Then i call the Tokenizer-function, i think there works anything fine.
But i am not absolutly sure.

Tokenizer (test, temp);

static void Tokenizer (char* input, char** returnV) {
    int i, j = 0, k = 0;
    char extracted[255];
     char separator = '/';

    for (i = 0; i <= StrLen(input); i++)
    {
     if (separator == input[i] || i == StrLen(input) ) // terminate if '/'
found or end of string reached
     {
      extracted[j] = '\0'; // terminate extracted String
      returnV[k] = MemPtrNew (sizeof(char) * StrLen (extracted));  //
Allocate memory for new String
      StrCopy (returnV[k], 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++;
 }

}



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

Reply via email to