Splitting a string by space in C
I'm working with C and through a socket I will be receiving a message with one space in it, I need to split the string into parts at the space. How would I go about doing this?
strtok_r is your friend.
Don't use plain strtok(), as it's NOT thread-safe.
Even on platforms where it is thread-safe (because the state is held in Thread-Local Storage), there is still the problem that the use of internal state means you cannot parse tokens from several strings simultaneously.
for example, if you write a function which uses strtok() to separate string A, your function cannot be called within the loop of a second function which is using strtok() to split string B.