Date: Sat, 17 Jan 2015 20:16:07 +0000 From: "Montgomery-Smith, Stephen" <stephen@missouri.edu> To: less xss <less.xss@gmail.com>, "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org> Subject: Re: ctrl-d appends characters to output Message-ID: <54BAC302.7050800@missouri.edu> 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
On 01/17/2015 11:59 AM, less xss wrote: > 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. >=20 > #include <stdio.h> >=20 > int main() { > double nc; >=20 > for (nc =3D 0; getchar() !=3D EOF; ++nc) { > ; /* syntactic null statement */ > } >=20 > printf("%.0f\n", nc); > } >=20 > $ ./a.out > 0D > $ I did a bit of experimenting with this issue. First, I cannot reproduce it on my Linux box. Second, this simpler program does the same thing: #include <stdio.h> int main() { while (getchar() !=3D EOF) { ; /* syntactic null statement */ } printf("\n"); } In this case I get: % ./a.out ^D % However, if I remove that last printf statement, then no ^D is displayed. Considering the inconsistent nature of when this ^D appears, I would prefer to call it a bug than a feature. But it must have been put there by design.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?54BAC302.7050800>