Wednesday, December 13th 2017, 12:11pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

knuta

Beginner

Date of registration: Nov 25th 2012

Posts: 26

1

Wednesday, May 17th 2017, 7:45am

printf("%02d", 5) prints "2d" instead of "05"

I've discovered that specifying the width of an integer in SEGGER Embedded Studio Release 3.12 Build 2017021000.31105 Linux x64 makes it fail to print a number, and instead prints part of the format string.

Consider this code:

Source code

1
2
3
4
    int i = 5;
    printf("Hello World %d!\n", i);
    printf("Hello World %2d!\n", i);
    printf("Hello World %02d!\n", i);


Expected output:

Source code

1
2
3
Hello World 5!
Hello World  5!
Hello World 05!


Actual output:

Source code

1
2
3
Hello World 5!
Hello World d!
Hello World 2d!


Steps to reproduce:

  • File -> New Project
  • Select "Create the project in a new solution"
  • Select "A C/C++ executable for a Cortex-M processor.", click Nex
  • Select "nRF52832_xxAA", click next
  • Leave everything as defaults, click next until wizard completes
  • Replace the "Hello World" printf with my code example above
  • Run the code and watch the Debug Console

I'm not sure if other devices are affected. The nRF52832_xxAA is a Cortex-M4 device.

knuta

Beginner

Date of registration: Nov 25th 2012

Posts: 26

2

Wednesday, May 17th 2017, 7:59am

Update: If I select "A C/C++ executable for a Cortex-M processor (internal tools and external GNU tools)." printf works as expected.

rgal

Beginner

Date of registration: Feb 16th 2016

Posts: 8

3

Saturday, July 8th 2017, 8:17pm

Hi,

I has similiar problem, in project options->code->printf/scanf->Printf Width/Precision Supported must be set to YES.