The following program shows one way:
#include <stdio.h>
Just call padf just like you would call printf , but with extra leading width and padding characters, and change the "real" format to exclude leading spaces or zeros, for example, change %8.2f to %.2f .
It will use standard argument arguments to work out the actual width of the argument, and then print enough indentation to fill to the desired width before returning the actual value. According to your requirements, the output of the above program:
**123.00 ****3.00
Obviously, this solution is located on the left - you can make it more general and convey whether you want it to stay left or right (for numbers / lines), but this is probably beyond the scope of the question.
source share