Working with data received by socket in C

0

I have a script that receives data via socket made in C, and I'm having trouble working with this data.

The data received from the client: "imei: 123123123,23123, tracker, 0.0 ......".

I need to receive this data and give an explode type to every "," same template used by PHP.

The code snippet where I'm having difficulty ...

while(client_size = recv(fd, msgin, sizeof(msgin), 0) != 0){

    //log
    myfile.open ("x.log",ios::app);
    myfile << put_time(localtime(&t), "%c") << " Data: " << msgin << endl;
    myfile.close();

    //------A intenção seria essa------------

    char *text = explode(msgin,',');
    .............
    ..........

    memset(msgin, 0, sizeof(msgin)); //Limpa o buffer
}

How to proceed?

    
asked by anonymous 15.03.2018 / 16:19

1 answer

-1

Use the strtok function of <string.h> . It breaks a string into several tokens, based on certain characters. More information at: strtok

    
15.03.2018 / 17:08