sprintf not functioning correctly

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

sprintf not functioning correctly

ソリューションへジャンプ
4,625件の閲覧回数
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,290件の閲覧回数
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,290件の閲覧回数
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,290件の閲覧回数
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,291件の閲覧回数
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,290件の閲覧回数
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 件の賞賛
返信