Jump to content
  • Advertisement
Sign in to follow this  
Muncher

the best way to parse a string of floats

This topic is 4746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i am reading in an array of floats that looks like this: point="-0.02125 -0.08879 -0.4612, 50.0 0.0 0.0, ....." and trying to put them in an array float data[50]; what is the best way of doing this? When i mean the easiest to read + most efficient, or the correct way it should be done. For example, one way would be to read strings between the commas one at a time, then use sscanf("%f",&element); or something, i'm sure theres a better way than that. Cheers Paul. using C++ btw

Share this post


Link to post
Share on other sites
Advertisement
a) Look carefully at the sscanf documentation: it has more features than people generally think.
b) What's the precise structure of your input string?
c) Look at std::stringstream.

Share this post


Link to post
Share on other sites
Quote:
Original post by Muncher
i just love the "look in the documentation" answers....


What more did you expect at 3AM? I notice you haven't even bothered answering my question.

anyway, consider something similar to

sscanf("%f %f %f,", data+i, data+i+1, data+i+2);

or

std::istringstream iss;
iss >> data >> data[i+1] >> data[i+2];
iss.ignore(1);


But since you're not motivated in checking the docs, neither am I motivated to check for correctness.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!