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?
I learned in this stack exchange question that the percent sign actually comes from zsh and means that the file didn't end with a newline, but zsh is showing one anyways to make your terminal output more clear & consistent. User geekq adds: I've now put PROMPT_EOL_MARK='' into my .
To obtain the character "%" in a format string, enter "%%", e.g. printf("The percentage is %d %%. *n",5); yields The percentage is 5 %.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With