-1

My Linux is Arch, my configuration is as follows:

Kernel: 5.13.13-arch1-1
Packages: 490 (pacman)
Shell: zsh 5.8
WM: dwm
Terminal: st
Terminal Font: Source Code Pro

When I use C output statements, such as printf and putchar('A');, if I don't add \r or \n at the end, I will get an extra '%' character on the terminal.

$ ./a.out
A%
$

This problem has troubled me for a long time, so that I don't know who is the problem, with dwm? With sh? With zhs?

dagelf
  • 1,468
  • 1
  • 14
  • 25
Ne C
  • 99
  • 6
  • 5
    don't paste code/text as images – tstanisl Sep 09 '21 at 11:56
  • If you add `'\n'` at the end the issue goes away? It's good to add `'\n'` at the end. Many *utilities* interpret line as "bunch of chars terminated by **and including** a newline" – pmg Sep 09 '21 at 11:56
  • Why is there a `c` in front of `./a.out`? – Fiddling Bits Sep 09 '21 at 11:57
  • Try `$ ./a.out | hd -c` – pmg Sep 09 '21 at 11:58
  • 1
    Please add plain text as (formatted) text directly into your question instead of pictures of consoles showing plain text. – Gerhardh Sep 09 '21 at 12:01
  • The first time I use stack overflow, I am very sorry, the previous C is my current folder name, and the output of ./a.out |od is:0000000 000101 0000001 ,I don't know how to add pictures in this, I'm very sorry – Ne C Sep 09 '21 at 12:06
  • 1
    That od output means `1` byte from `./a.out` with the octal value `000101` which is `A` (`65`), so the extra character is not from your executable. – pmg Sep 09 '21 at 12:21
  • Thank you very much for your criticisms and corrections. The solution I have found, as described in the answer, I only need to modify it in .zsh – Ne C Sep 09 '21 at 12:34
  • 1
    @tstanisl: In this case, the image of terminal window text is relevant and appropriate, as the coloring and altered background convey information about the source or nature of the various text, and the question goes to the display of text, rather than its content *per se*. For example, the black-on-white of the `%` contrasted with the white-on-black `A` is a clue that the `%` was not output by the program. – Eric Postpischil Sep 09 '21 at 12:35

1 Answers1

4

This is a feature of zsh to show when a program has ended without a final newline and to distinguish zsh’s command prompt from the program output.

You can disable it with the zsh command PROMPT_EOL_MARK=''. You can also set it to something else, such as PROMPT_EOL_MARK=' -- The program did not end with a newline.'.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312