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?

Answers


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.


Need Your Help

Override layoutSubviews to call and then find and reposition the button's view

iphone objective-c xcode cocoa-touch uinavigationbar

I'm trying to reposition my UIBarButtonItem so that it sits with it's edges against the top and right of the UINavigationBar. I found this accepted answer on how to do this, but I don't really unde...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.