[SOLVED] RTT: string padding does not work

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] RTT: string padding does not work

    I'm trying to use the segger RTT SEGGER_RTT_vprintf to print a string with padding.

    The following code doesn't seem to work properly

    C Source Code

    1. SEGGER_RTT_vprintf(0, "%d %-10s - %s", 10, "TEST", "module");

    The padding behaviour doesn't work as mentioned in the documentation.

    Expected10 TEST - module
    Actual10 TEST - module

    When looking at the code, in "%s" mode, the FieldWith seems ignored

    C Source Code

    1. case 's':
    2. {
    3. const char * s = va_arg(*pParamList, const char *);
    4. do {
    5. c = *s;
    6. s++;
    7. if (c == '\0') {
    8. break;
    9. }
    10. _StoreChar(&BufferDesc, c);
    11. } while (BufferDesc.ReturnValue >= 0);
    12. }
    13. break;
    Display All

    RTT version: 7.84d

  • Hi Gabriel,
    this is intentional.

    SEGGER_RTT_printf() is (by far) not a complete printf() implementation.
    Flags, FieldWidth and Precision will be ignored for specifiers s & c.

    Unfortunately, this information was missing from the API documentation in the Wiki.
    We just added this information to prevent confusion:

    For your specific use case, I would suggest to use snprintf() or similar,
    provided by the library of your choice.

    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.