tags:

views:

177

answers:

2

hi I am using IAR c compiler, I am trying to print floating point value like

printf("version number: %f\n",1.4);

but I am always getting like below in console

version number:ERROR

help please thanks in advance kudi

A: 

The format string for the printf function can specify floating point representations with a more explicit string:

printf("version number: %3.1f\n", 1.4);

I think this is the cause of the error message.

The '%3.1f' tells printf to use 3 characters, with one after the decimal place. The output should be

version number: 1.4

EDIT: Kudi, it seems the printf() function in the IAR compiler is quite different from the K&R printf() function.

This link is just one example which leads me to think that my copy of K&R is going to be no help at all. Sorry about that.

pavium
thanks for fast replay ,i tried what u said the output was like belowversion_number:ERROR1f
kudi
I noticed that you said IAR c compiler. I was referring to 'The C Programming Language' by Kernighan and Ritchie. Maybe there's some difference in syntax. Actually, looking at that very old book, it's not clear that %3.1f would be acceptable. I suggest you go back to just %f and leave out the \n
pavium
+1  A: 

The error is probably due to your dlib configuration. Because of the focus on embedded targets with resource restrictions the behaviour/feature set of the iar c library (dlib) is configurable.

Look at Project/Options/General Options/Library Options.

From the docs:

*CHOOSING PRINTF FORMATTER The printf function uses a formatter called _Printf. The default version is quite large, and provides facilities not required in many embedded applications. To reduce the memory consumption, three smaller, alternative versions are also provided in the standard C/EC++ library.*

The #define _DLIB_PRINTF_SPECIFIER_FLOAT is available if printf knows floats.

dantje