This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sprintf width problem

I'm having trouble with the C51 sprintf formats.
sprintf does not pad the output according to the width field

sprintf(rs_send_line,"%2d:%2d -> ",hrs,(int)(m-(hrs*60)));
sprintf(&rs_send_line[9],"%4.0fV at %3buuA %5.0fVhrs",v_last,current_per_strip,run_vhrs);

yields the following output

"4:00 -> 500V at 7uA 2000Vhrs"

Why is the output not padded with blanks per the width field?

Any suggestions would be appreciated.

Thanks
Allen

Parents
  • Are you sure the code you've posted is really the code that is producing that output? I ask because the second %d has left padded the output with zeros (which seems to be exactly what you want) even though you haven't specified the zero flag.

    What version of the compiler are you using?

    Stefan

Reply
  • Are you sure the code you've posted is really the code that is producing that output? I ask because the second %d has left padded the output with zeros (which seems to be exactly what you want) even though you haven't specified the zero flag.

    What version of the compiler are you using?

    Stefan

Children
No data