From owner-freebsd-hackers@FreeBSD.ORG Sat Jan 17 20:17:20 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2ED0484B for ; Sat, 17 Jan 2015 20:17:20 +0000 (UTC) Received: from um-nip3-missouri-out.um.umsystem.edu (um-nip3-missouri-out.um.umsystem.edu [198.209.49.163]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "um-tip1.um.umsystem.edu", Issuer "InCommon RSA Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B6306324 for ; Sat, 17 Jan 2015 20:17:18 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiUFABvCulTPoJ7U/2dsb2JhbABagwaBLsQJhUeCTwKBDkMBAQEBAQN6hA0BBXgRAgEIGAkWDwkDAgECASAlAgQBDAgBAYgoy0QBg1cBCwEfj0Y6hCkFjkybGSKDboI0fgEBAQ X-IPAS-Result: AiUFABvCulTPoJ7U/2dsb2JhbABagwaBLsQJhUeCTwKBDkMBAQEBAQN6hA0BBXgRAgEIGAkWDwkDAgECASAlAgQBDAgBAYgoy0QBg1cBCwEfj0Y6hCkFjkybGSKDboI0fgEBAQ Received: from um-ncas6.um.umsystem.edu ([207.160.158.212]) by um-nip3-exch-relay.um.umsystem.edu with ESMTP; 17 Jan 2015 14:16:07 -0600 Received: from UM-MBX-N02.um.umsystem.edu ([169.254.5.23]) by UM-NCAS6.um.umsystem.edu ([207.160.158.212]) with mapi id 14.03.0210.002; Sat, 17 Jan 2015 14:16:07 -0600 From: "Montgomery-Smith, Stephen" To: less xss , "freebsd-hackers@freebsd.org" Subject: Re: ctrl-d appends characters to output Thread-Topic: ctrl-d appends characters to output Thread-Index: AQHQMoq4BXOKvIQ6l0u+m3Cgq79pjZzFJFMA Date: Sat, 17 Jan 2015 20:16:07 +0000 Message-ID: <54BAC302.7050800@missouri.edu> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 x-originating-ip: [207.160.158.206] Content-Type: text/plain; charset="Windows-1252" Content-ID: <311E36D74088C645B99EAA20E4AD076B@missouri.edu> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jan 2015 20:17:20 -0000 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 >=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 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.