Thread: printf formating!

  1. #1
    Wymiatacz
    Join Date
    Jan 2007
    Location
    Far away
    Posts
    6

    Question printf formating!

    Hi all,

    I'm in the middle of type out an software from Keil compiler for '51 to IAR compiler for H8.
    The issue is that I found:

    Code:
    unsigned char buffer[40];
    unsigned char variable1, variable2;
    ....
    sprintf(buffer,"%0.2d %2.2d", (int)variable1, (int)variable2);
    ....
    I cant check whats the result of that statement in Keil compiler, but in IAR result is:

    Code:
    0.2d 2.2d
    What has no sense. Any ideas?
    Better is an enemy of good ...

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Try just %d

    I wouldn't bank on the standard C library for embedded compilers like the ones you're using to have FULL support for every single option within the ANSI-C standard.

    I'm guessing that since it doesn't know about that extended format, it just copies it to the buffer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Wymiatacz
    Join Date
    Jan 2007
    Location
    Far away
    Posts
    6

    Thumbs up IAR does not support %0.2d formating.

    Quote Originally Posted by Salem
    Try just %d

    I wouldn't bank on the standard C library for embedded compilers like the ones you're using to have FULL support for every single option within the ANSI-C standard.

    I'm guessing that since it doesn't know about that extended format, it just copies it to the buffer.

    I know now that IAR does not support %0.2d formating. In Keil it makes "08" from "8". So I have to write my own format function. Thanks for reply.
    Better is an enemy of good ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IF CONDITION plese help
    By birumut in forum C Programming
    Replies: 12
    Last Post: 03-06-2009, 09:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM