FoppyOmega
FoppyOmega

Reputation: 447

Getting a substring in C

I have a string in the following format: "R: 625.5m E:-32768m"

What's the most efficient way to pull out the 625.5?

Upvotes: 1

Views: 600

Answers (2)

Randolpho
Randolpho

Reputation: 56381

Your best bet is to use sscanf to read formatted information from the string.

sscanf(mystr, "R: %f", &myFloat);

Upvotes: 1

Eiko
Eiko

Reputation: 25632

sscanf is a good candiate to parse simple strings with fixed format.

Upvotes: 1

Related Questions