Date: Sat, 17 Jan 2015 11:43:08 -0800 From: John-Mark Gurney <jmg@funkthat.com> To: less xss <less.xss@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: ctrl-d appends characters to output Message-ID: <20150117194308.GH1949@funkthat.com> 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
less xss wrote this message on Sat, Jan 17, 2015 at 12:59 -0500: > 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 problem exists on pretty much any Unix based platform and is not FreeBSD specific... The D is not getting appended to your output... If you changed your printf to include a space or two before the new line, you wouldn't see the D... the D is left after the kernel echoed ^D in response to your ctrl-D. If you redirect the output to a file and examined the output, there would be no D in your output... Or if you provided input from another source that didn't require an EOF to trigger it, such as: $echo | ./t 1 -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150117194308.GH1949>