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 strongm 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
Oct 15, 2002
15
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

Replies
3
Views
66
  • Locked
  • Question
Replies
4
Views
80
Replies
3
Views
123

Part and Inventory Search

Sponsor

Back
Top