Versão limpa em 04/09/2014. Telnet funcionando.

Dependencies:   EthernetInterface mbed-rtos mbed NTPClient

Functions/Split.c

Committer:
rebonatto
Date:
2014-09-04
Revision:
0:66d8bd1f9d4c

File content as of revision 0:66d8bd1f9d4c:

/*
 * Split.c
 *
 *  Created on: 12/04/2012
 *      Author: francisco
 */

#include "Split.h"

int split(char* str,char* delim,char*** ret )
{
    char *p = NULL;
    char *e = NULL;
    char **array = NULL;
    int qty = 0;
    int len = strlen(str);

    p = str;

    e = strstr(p,delim);

    while( e != NULL)
    {
        qty++;
        if(qty==1)
            array = (char**)malloc(sizeof(char*)*qty);
        else
            array = (char**)realloc(array,sizeof(char*)*qty);

        array[qty-1] = p;
        *e = '\0';
        p = e + strlen(delim);
        e = strstr(p,delim);
    }
    if(p-str < len)
    {
        qty++;
        if(qty==1)
            array = (char**)malloc(sizeof(char*)*qty);
        else
            array = (char**)realloc(array,sizeof(char*)*qty);
        array[qty-1] = p;
    }

    *ret = array;
    return qty;
}