Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

sprintf format issue

Hi,

I am doing a simple thing with string formatting:

sprintf(tmp_str,"%d.%d.%3d", version.major, version.minor, version.patch);

The version structure has values { 0, 5, 1 } and char tmp_str[20]. I want to achieve string like "0.5.001". Instead of getting this format, I am getting "0.5.d". 

For a curiosity I tried to change the format to "%3d.%d.%d" and I got "d.0.5". Format "%d.%d.%d" works as expected - 0.5.1.

I am using SDK 17.0.2 and SES 5.60.

Can somebody advise me how to brush sprintf to work as expected? I am not asking for workarounds how to get the expected string format rather to get sprintf working.

Thanx.

Best regards,

peter

Related