cprintfzsh

Getting a weird percent sign in printf output in terminal with C


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. enter image description here

Can anyone tell me why this is happening?


Solution

  • 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.