Search code examples
cstringparsingdvb

split dvb url address into separate values


Let assume we have such URL:

dvb://1.3f3.255c.15

my question is how to parse this address in following way:

val1 = 1
val2 = 3f3
val3 = 255c
val4 = 15

First idea is to use strchr() from standard C library, but maybe done it before. I would like to make it as simple as possible. When I will succeed I will put my solution.

Best Regards


Solution

  • You could use strtok

    char dvb_url[] = "dvb://1.3f3.255c.15";
    
    //Begin stripping the scheme (dvb:/)
    char *tokenized = strtok(dvb_url, "/");
    //Finish stripping scheme
    tokenized = strtok(NULL, "/.");
    
    while(tokenized != NULL)
    {
        //Store in variable here            
        printf("%s\n", tokenized);
        tokenized = strtok(NULL, ".");
    }