Ver Mensaje Individual
  #3 (permalink)  
Antiguo 19/11/2010, 19:06
Trovaz
 
Fecha de Ingreso: octubre-2010
Ubicación: Edo. de México
Mensajes: 94
Antigüedad: 14 años, 2 meses
Puntos: 9
Respuesta: how could I obtain the same result like with StringTokenizer in Java [strt

Código:
DESCRIPTION
     This interface is obsoleted by strsep(3).

     The strtok() function is used to isolate sequential tokens in a null-ter-
     minated string, str.  These tokens are separated in the string by at
     least one of the characters in sep.  The first time that strtok() is
     called, str should be specified; subsequent calls, wishing to obtain fur-
     ther tokens from the same string, should pass a null pointer instead.
     The separator string, sep, must be supplied each time, and may change
     between calls.

     The implementation will behave as if no library function calls strtok().

     The strtok_r() function is a reentrant version of strtok().  The context
     pointer last must be provided on each call.  The strtok_r() function may
     also be used to nest two parsing loops within one another, as long as
     separate context pointers are used.

     The strtok() and strtok_r() functions return a pointer to the beginning
     of each subsequent token in the string, after replacing the token itself
     with a NUL character.  When no more tokens remain, a null pointer is
     returned.


EXAMPLES
     The following uses strtok_r() to parse two strings using separate con-
     texts:

     char test[80], blah[80];
     char *sep = "\\/:;=-";
     char *word, *phrase, *brkt, *brkb;

     strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function.");

     for (word = strtok_r(test, sep, &brkt);
          word;
          word = strtok_r(NULL, sep, &brkt))
     {
         strcpy(blah, "blah:blat:blab:blag");

         for (phrase = strtok_r(blah, sep, &brkb);
              phrase;
              phrase = strtok_r(NULL, sep, &brkb))
         {
             printf("So far we're at %s:%s\n", word, phrase);
         }
     }
source: man 3 strtok

everytime you need info about a particular command/function check his man page. If u are under linux/unix/mac just type "man <section> <command/function>" where section is the number of the section you want to check out (section 3 goes for system calls and functions i think).

I hope my answer helped you

Greetings++