sprintf not functioning correctly

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

sprintf not functioning correctly

Jump to solution
3,391 Views
christopher_hes
Contributor I

I am working on a project in MCUXpresso that was originally written in code warrior. I am having difficulty using a sprintf() function and the problem seems to be with MCUXpresso. I have checked that I am using the original compiler and I am using the Redlib semihost C library.  Below is the code:

char tString[50];

float current = 1.2;

sprintf(tString, "%3.0f",current);

After stepping through this code, the first three entries of tString are 32 ' '.  What could be causing this issue?

0 Kudos
Reply
1 Solution
3,056 Views
BlackNight
NXP Employee
NXP Employee

I see you still have that CR_INTEGER_PRINTF in the list of defines. Remove it.

I hope this helps,

Erich

View solution in original post

0 Kudos
Reply
4 Replies
3,056 Views
BlackNight
NXP Employee
NXP Employee

Are you using RedLib (the default)?

If yes, see https://community.nxp.com/docs/DOC-342727 

I hope this helps,

Erich

0 Kudos
Reply
3,056 Views
christopher_hes
Contributor I

I am using RedLib,  I followed the instructions in the article you have referenced and when I opened that window the only directive from the article was PRINTF_FLOAT_ENABLE=0.  I modified the directives as seen below and this has still not solved the issue.  Additionally, I have included a snip of the tString after sprintf is called.

pastedImage_1.png

pastedImage_3.png

0 Kudos
Reply
3,057 Views
BlackNight
NXP Employee
NXP Employee

I see you still have that CR_INTEGER_PRINTF in the list of defines. Remove it.

I hope this helps,

Erich

0 Kudos
Reply
3,056 Views
christopher_hes
Contributor I

This seems to have solved the issue, thank you.  I additionally found that it works using the NewLibNano library and selecting enable printf float and enable scanf float in the Managed Linker Script.

0 Kudos
Reply