Date: Sat, 17 Jan 2015 20:38:48 +0100 From: Matthias Apitz <guru@unixarea.de> To: less xss <less.xss@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: ctrl-d appends characters to output Message-ID: <20150117193848.GA1394@c720-r276659> In-Reply-To: <CAGcjGpP0t3%2BcJLRHS5Ggfjao9Vcy0xosAg2KqBWgVA_NtKoNgA@mail.gmail.com> References: <CAGcjGpP0t3%2BcJLRHS5Ggfjao9Vcy0xosAg2KqBWgVA_NtKoNgA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
El día Saturday, January 17, 2015 a las 12:59:05PM -0500, less xss escribió: > I've searched around quite a bit with no luck on this matter. I currently > have an issue where I send EOF (ctrl-d) to some simple K&R2 exercises and > the terminal returns the D character appended to my data when EOF is sent. > I wish to prevent any and all extra characters from being appended and I > would also like to understand why it's happening. The following code > is an example exercise from K&R2 that yield said problem. > > #include <stdio.h> > > int main() { > double nc; > > for (nc = 0; getchar() != EOF; ++nc) { > ; /* syntactic null statement */ > } > > printf("%.0f\n", nc); > } > > $ ./a.out > 0D > $ This is just a display issue of your typed Ctrl-d; the '0D' is the '^D' where the '^' is overwritten by your output of the value of 'nc'; run your a.out as: $ ./a.out < /dev/null or change the printf(3) line to: printf("\n%.0f\n", nc); HIH matthias -- Matthias Apitz, guru@unixarea.de, http://www.unixarea.de/ +49-170-4527211 1989-2014: The Wall was torn down so that we go to war together again. El Muro ha sido derribado para que nos unimos en ir a la guerra otra vez. Diese Grenze wurde aufgehoben damit wir gemeinsam wieder in den Krieg ziehen.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150117193848.GA1394>