Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. char **split ( const char *s1, const char *s2) {
  6.  
  7.     char **lista;
  8.     char *aux = s1;
  9.     char *token_Ptr;
  10.     int i = 0;
  11.     
  12.     lista = (char **) malloc (sizeof (char *));
  13.     token_Ptr = strtok(aux, s2);
  14.     lista[i] = token_Ptr;
  15.     while(token_Ptr != NULL)
  16.     {
  17.         lista = (char **)realloc(lista, sizeof(char*) * (i + 1));
  18.         token_Ptr = strtok(NULL, s2);
  19.         i++;
  20.         lista[i] = token_Ptr;
  21.     }
  22.     return lista;
  23. }
  24.  
  25. int main ( int argc , char *argv[]) {
  26.  
  27.     char **MILISTA;
  28.     int i;
  29.  
  30.     if (argc==2) {
  31.         printf ("Cadena: '%s'\n",argv[1]);
  32.         MILISTA= split(argv[1]," ");
  33.         i=0;
  34.         puts("----------------TOKENS------------");
  35.         while (MILISTA[i]!=NULL) {
  36.             printf("%s, " , MILISTA[i++]);
  37.         }
  38.         printf("\n");
  39.         puts("----------------FIN---------------");
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement