Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- char **split ( const char *s1, const char *s2) {
- char **lista;
- char *aux = s1;
- char *token_Ptr;
- int i = 0;
- lista = (char **) malloc (sizeof (char *));
- token_Ptr = strtok(aux, s2);
- lista[i] = token_Ptr;
- while(token_Ptr != NULL)
- {
- lista = (char **)realloc(lista, sizeof(char*) * (i + 1));
- token_Ptr = strtok(NULL, s2);
- i++;
- lista[i] = token_Ptr;
- }
- return lista;
- }
- int main ( int argc , char *argv[]) {
- char **MILISTA;
- int i;
- if (argc==2) {
- printf ("Cadena: '%s'\n",argv[1]);
- MILISTA= split(argv[1]," ");
- i=0;
- puts("----------------TOKENS------------");
- while (MILISTA[i]!=NULL) {
- printf("%s, " , MILISTA[i++]);
- }
- printf("\n");
- puts("----------------FIN---------------");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement