From owner-freebsd-hackers@FreeBSD.ORG Sat Jan 17 21:02:29 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 11091F10 for ; Sat, 17 Jan 2015 21:02:29 +0000 (UTC) Received: from um-nip4-missouri-out.um.umsystem.edu (um-nip4-missouri-out.um.umsystem.edu [198.209.49.177]) (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 97F3395D for ; Sat, 17 Jan 2015 21:02:28 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiUFAB/NulTPoJ7U/2dsb2JhbABZgwaBLsQJhUeCTwKBDkMBAQEBAQN6hA0BBXgRAgEIGAkWDwkDAgECASAlAgQBDAgBAYgoyzwBg1cBCgEBAR6PRjqEKQWOTJsZIoNugjR+AQEB X-IPAS-Result: AiUFAB/NulTPoJ7U/2dsb2JhbABZgwaBLsQJhUeCTwKBDkMBAQEBAQN6hA0BBXgRAgEIGAkWDwkDAgECASAlAgQBDAgBAYgoyzwBg1cBCgEBAR6PRjqEKQWOTJsZIoNugjR+AQEB Received: from um-ncas6.um.umsystem.edu ([207.160.158.212]) by um-nip4-exch-relay.um.umsystem.edu with ESMTP; 17 Jan 2015 15:01:06 -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 15:01:05 -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+m3Cgq79pjZzFJFMAgAAMkQA= Date: Sat, 17 Jan 2015 21:01:04 +0000 Message-ID: <54BACD8C.3050703@missouri.edu> References: <54BAC302.7050800@missouri.edu> In-Reply-To: <54BAC302.7050800@missouri.edu> 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: <9BBE76D5F2FDD34EAFCA44F867181257@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 21:02:29 -0000 On 01/17/2015 02:16 PM, Montgomery-Smith, Stephen wrote: > On 01/17/2015 11:59 AM, less xss wrote: >> I've searched around quite a bit with no luck on this matter. I currentl= y >> have an issue where I send EOF (ctrl-d) to some simple K&R2 exercises an= d >> the terminal returns the D character appended to my data when EOF is sen= t. >> 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 >> >> int main() { >> double nc; >> >> for (nc =3D 0; getchar() !=3D EOF; ++nc) { >> ; /* syntactic null statement */ >> } >> >> printf("%.0f\n", nc); >> } >> >> $ ./a.out >> 0D >> $ >=20 > 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: >=20 > #include >=20 > int main() { >=20 > while (getchar() !=3D EOF) { > ; /* syntactic null statement */ > } >=20 > printf("\n"); > } >=20 > In this case I get: >=20 > % ./a.out > ^D > % >=20 > However, if I remove that last printf statement, then no ^D is displayed. >=20 > 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. OK, that last printf is NOT responsible for the ^D. It is just that the prompt wipes it out. Try this code: #include #include int main() { while (getchar() !=3D EOF) { ; /* syntactic null statement */ } sleep(10); } Then the ^D shows until the prompt appears 10 seconds later.