sprintf not functioning correctly

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

sprintf not functioning correctly

跳至解决方案
4,642 次查看
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 项奖励
回复
1 解答
4,307 次查看
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 项奖励
回复
4 回复数
4,307 次查看
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 项奖励
回复
4,307 次查看
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 项奖励
回复
4,308 次查看
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 项奖励
回复
4,307 次查看
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 项奖励
回复