Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've seen this one - it confused me, too.</p> <p>The terminal is echoing <code>^D</code> and then the <code>0</code> is output from the program, overwriting the caret.</p> <p>You can demonstrate this by changing the print format in your program to <code>"\n%d\n"</code>.</p> <hr> <p>When asked 'Why?', I went exploring. The answer is in the tty settings. For my terminal, the output from <code>stty -a</code> is:</p> <pre><code>speed 9600 baud; 65 rows; 120 columns; lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo -extproc iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8 -ignbrk brkint -inpck -ignpar -parmrk oflags: opost onlcr -oxtabs -onocr -onlret cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow -dtrflow -mdmbuf cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = &lt;undef&gt;; eol2 = &lt;undef&gt;; erase = ^?; intr = ^C; kill = ^X; lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W; </code></pre> <p>Notice the <code>echoctl</code> at the end of the second line - it is for 'echo control characters'.</p> <pre><code>$ stty -echoctl $ cat &gt; /dev/null asdsadasd $ stty echoctl $ cat &gt; /dev/null asasada^D $ </code></pre> <p>You can't see it, but for each <code>cat</code> command, I typed a <kbd>Control-D</kbd> at the end of the line of <code>asd</code> characters, and a second one after hitting return. The prompt erased the second echoed <code>^D</code> in the second example.</p> <p>So, if you don't like the control characters being echoed, turn the echoing off:</p> <pre><code>stty -echoctl </code></pre> <p>The shell can also get in the way; I experimented with <kbd>Control-R</kbd> and my shell (<code>bash</code>) decided to go into</p> <pre><code>(reverse-i-search)`': aasadasdadadasdadadadadadsad </code></pre> <p>I'd typed the unoriginal sequence of 'asd' characters and then typed <kbd>Control-R</kbd>, and this is where I ended up in the shell. I interrupted; I'm not sure what a reverse-i-search is, but I suspect it is Emacs-ish; it was not what I expected.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload