atof is not working

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

atof is not working

Jump to solution
2,351 Views
kandhu26
Contributor II

Hi everyone,

 

     I am using K60 & MQX4.0 version. atoi is working fine for me & atof is not working. I have enabled _EWL_FLOATING_POINT in ansi_params.h too. Still atof is not working for me.. Please anyone help me in these.

Labels (1)
Tags (1)
1 Solution
1,477 Views
kandhu26
Contributor II

Hi guys,

     Thank you for all your support.. Today i fixed the bug.. When it was not working i have included only #include <string.h>.

Now i have included #include <stdlib.h> too.. Now the following code working perfectly with atof feature..

int integer;
double flot;
uchar ascii_int[] = "12345";

uchar ascii_float[] = "54321.54321";

integer = atoi((const char*)ascii_int);
printf("The integer value is %d\n\r", integer);
flot = atof((const char*)ascii_float);
printf("The float value is %f\n\r", flot);

The output follows,

The integer value is 12345

The flot value is 54321.54321


     The one more change required to make it work atof was type casting..

View solution in original post

0 Kudos
6 Replies
1,478 Views
kandhu26
Contributor II

Hi guys,

     Thank you for all your support.. Today i fixed the bug.. When it was not working i have included only #include <string.h>.

Now i have included #include <stdlib.h> too.. Now the following code working perfectly with atof feature..

int integer;
double flot;
uchar ascii_int[] = "12345";

uchar ascii_float[] = "54321.54321";

integer = atoi((const char*)ascii_int);
printf("The integer value is %d\n\r", integer);
flot = atof((const char*)ascii_float);
printf("The float value is %f\n\r", flot);

The output follows,

The integer value is 12345

The flot value is 54321.54321


     The one more change required to make it work atof was type casting..

0 Kudos
1,477 Views
deepakrana
NXP Employee
NXP Employee

Finally u got it working , I told you so

Best Regards

Deepak Kumar Rana

Field Application Engineer

H.P: +91 9916927803

Freescale Semiconductors

Campus 1C ,4th Floor Ecospace

Sarjapur Outer Ring Road

Banglore India 560037

1,477 Views
c0170
Senior Contributor III

Hello kandha samy,

any code for sharing? How do you invoke atoi and how atof? How does atof fail?

Please read a following post which explains what you should include in your bug/problem report:

How to post in the MQX section and get an answer!

Regards,

c0170

0 Kudos
1,477 Views
kandhu26
Contributor II

Hi Martin,

          Thank you for your reply.. Here is the test code which i have tried..

int integer;
float flot;
uchar ascii_int[] = "12345";

uchar ascii_float[] = "54321.54321";

integer = atoi(ascii_int);
printf("The integer value is %d\n\r", integer);
flot = atof(ascii_float);
printf("The float value is %f\n\r", flot);

The output follows,

The integer value is 12345

The flot value is 1643769856.000000

So the output shows atoi is working fine & atof is not giving proper output. To make sure that there is some problem with atof i have done one more test..

int integer;
float flot;
uchar ascii_int[] = "12345";

uchar ascii_float[] = "54321.54321";

integer = atoi(ascii_int);
printf("The integer value is %d\n\r", integer);
integer = atoi(ascii_float);
printf("The float value is %d\n\r", integer);

The output follows,

The integer value is 12345

The flot value is 54321

So, The above test that i concluded atoi is working perfectly & there is some issue with atof...

0 Kudos
1,477 Views
deepakrana
NXP Employee
NXP Employee

hi

This is a CW compiler problem

Needs a library bug fix.

0 Kudos
1,477 Views
deepakrana
NXP Employee
NXP Employee

Hi

In the properties of the project in the Librarian you need to choose the MOdel  C9xx

Print format  int_FP

In the MQX BSP you need to enable

#define MQX_INCLUDE_FLOATING_POINT_IO  1


This should solve the problem in MQX system

0 Kudos