From owner-freebsd-hackers@FreeBSD.ORG Sat Jan 17 19:43:15 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 3F481A6 for ; Sat, 17 Jan 2015 19:43:15 +0000 (UTC) Received: from gold.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "gold.funkthat.com", Issuer "gold.funkthat.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 03925FD6 for ; Sat, 17 Jan 2015 19:43:14 +0000 (UTC) Received: from gold.funkthat.com (localhost [127.0.0.1]) by gold.funkthat.com (8.14.5/8.14.5) with ESMTP id t0HJh8Z9023074 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 17 Jan 2015 11:43:08 -0800 (PST) (envelope-from jmg@gold.funkthat.com) Received: (from jmg@localhost) by gold.funkthat.com (8.14.5/8.14.5/Submit) id t0HJh8lr023073; Sat, 17 Jan 2015 11:43:08 -0800 (PST) (envelope-from jmg) Date: Sat, 17 Jan 2015 11:43:08 -0800 From: John-Mark Gurney To: less xss Subject: Re: ctrl-d appends characters to output Message-ID: <20150117194308.GH1949@funkthat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 9.1-PRERELEASE amd64 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.7 (gold.funkthat.com [127.0.0.1]); Sat, 17 Jan 2015 11:43:08 -0800 (PST) Cc: freebsd-hackers@freebsd.org 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 19:43:15 -0000 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 > > 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."