Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

type conversion

Status
Not open for further replies.

ralphtan

Technical User
Joined
Oct 15, 2002
Messages
15
Location
SG
Hi,

if I have a char ptr with data and I want to convert to float, how can I do it?

eg

char* data="10000";
float F;

F = *data; /* this way */
 
There are a number of possibilities:

if (1 == sscanf(data,"%f",&F))
conversion OK
else
conversion failed

OR

F = atof(data)

or (better)

F = strtod(data,&end);

The strtod provides error values when the data is out of range, or just wrong. Look at the manual page for that.

HTH
Pieter

 
Status
Not open for further replies.

Similar threads

  • Locked
  • Question Question
Replies
3
Views
304
  • Locked
  • Question Question
Replies
4
Views
299
Replies
8
Views
352
  • Locked
  • Question Question
Replies
3
Views
493

Part and Inventory Search

Sponsor

Back
Top