Right aligning using printf_P in C

Viewed 476

I am attempting to get an output of:

Score: 
    0

but my output keeps coming out like

Score:        0

this is what I have implemented:

move_cursor(30,4);
printf_P(PSTR("Score : %8d\n"), get_score());
move_cursor(37, 8);

we are writing the score in Putty, from AVR to serial. What am I doing wrong?

1 Answers

Q: If you want "0" on a separate line ... then shouldn't you put a matching `\n' in your format statement?

Q: If You want it right-aligned at column 6, then shouldn't your format statement be %6?

EXAMPLE: printf_P(PSTR("Score :\n%6d\n"), get_score());

PS:

As you're probably aware, "printf_P()" isn't standard C; it's AVR-specific.

Related