3/06/2014

(C, C++) converting char * to float , strtod and atof functions

#include < stdlib.h>
#include < stdio.h>

void main()
{
  char *floatText = "34.12";
  double Afloat = strtod(floatText ,NULL);
  float Bfloat = atof(floatText );
  printf("%f, %f",Afloat ,Bfloat );

}



/* Output */
34.120000, 34.120000

No comments:

Post a Comment