From owner-freebsd-hackers@FreeBSD.ORG Sat Jan 17 19:58: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 ABEB95CB for ; Sat, 17 Jan 2015 19:58:15 +0000 (UTC) Received: from ms-10.1blu.de (ms-10.1blu.de [178.254.4.101]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6AF2315F for ; Sat, 17 Jan 2015 19:58:14 +0000 (UTC) Received: from [89.15.237.229] (helo=c720-r276659) by ms-10.1blu.de with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1YCZCw-0001Ru-Fu; Sat, 17 Jan 2015 20:38:54 +0100 Date: Sat, 17 Jan 2015 20:38:48 +0100 From: Matthias Apitz To: less xss Subject: Re: ctrl-d appends characters to output Message-ID: <20150117193848.GA1394@c720-r276659> Reply-To: Matthias Apitz Mail-Followup-To: Matthias Apitz , less xss , freebsd-hackers@freebsd.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Operating-System: FreeBSD 11.0-CURRENT r269739 (i386) User-Agent: Mutt/1.5.23 (2014-03-12) X-Con-Id: 51246 X-Con-U: 0-guru X-Originating-IP: 89.15.237.229 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:58:15 -0000 El día Saturday, January 17, 2015 a las 12:59:05PM -0500, less xss escribió: > 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 is just a display issue of your typed Ctrl-d; the '0D' is the '^D' where the '^' is overwritten by your output of the value of 'nc'; run your a.out as: $ ./a.out < /dev/null or change the printf(3) line to: printf("\n%.0f\n", nc); HIH matthias -- Matthias Apitz, guru@unixarea.de, http://www.unixarea.de/ +49-170-4527211 1989-2014: The Wall was torn down so that we go to war together again. El Muro ha sido derribado para que nos unimos en ir a la guerra otra vez. Diese Grenze wurde aufgehoben damit wir gemeinsam wieder in den Krieg ziehen.