I am new to C and was wondering how I could do something like this:
I have a string coming in like this through a socket (it could vary)
"GET OK 1045 \r\nTHE RED RIDING HOOD"
Now I may get it in chunks of it and not completely like
"GET OK 10"
And later on
"45 \r\nTHE RED RIDING HOOD"
What is the best way to split when it finds the \r\n and store what came before it in a variable and what comes after it in another one.
I have tried strtok() but it just became way to messy and was getting errors
I tried sscanf() but since i may be getting chunks I can never get it to format it correctly into my variables. I am sure there my be a easy way to do this in a while loop but the splitting is what is getting me.
while((items_read = read(sock, stories_buffer, BUF_SIZE)) > 0) {
//how do i check on stories_buffer as it comes and split it based on delimiter \r\n
}