printf formating!

This is a discussion on printf formating! within the C Programming forums, part of the General Programming Boards category; Hi all, I'm in the middle of type out an software from Keil compiler for '51 to IAR compiler for ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 08:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 08:38 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04: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, 08:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21