Getting a weird percent sign in printf output in terminal with C
CPrintfZshC Problem Overview
I have this printf
statement at the end of my program:
printf("%d", total_candies);
total_candies
is an int
, and while I expect everything to work correctly, along with the actual number, I'm getting a weird percent sign at the end.
Can anyone tell me why this is happening?
C Solutions
Solution 1 - C
When (non-null) output from a program doesn't include a trailing newline, zsh adds that color-inverted %
to indicate that and moves to the next line before printing the prompt; it's generally more convenient than bash's behavior, just starting the command prompt where the output ended.
Solution 2 - C
In zsh
PROMPT_SP
Attempt to preserve a partial line (i.e. a line that did not end with a newline) that would otherwise be covered up by the command prompt due to the PROMPT_CR
option. This works by outputting some cursor-control characters, including a series of spaces, that should make the terminal wrap to the next line when a partial line is present (note that this is only successful if your terminal has automatic margins, which is typical).
When a partial line is preserved, by default you will see an inverse+bold character at the end of the partial line
: a ‘%’
for a normal user
or a ‘#’ for
root. If set, the shell parameter
PROMPT_EOL_MARK` can be used to customize how the end of partial lines are shown.