From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 10 23:00:22 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AB7991065674 for ; Tue, 10 Mar 2009 23:00:22 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from server.mypc.hu (server.mypc.hu [87.229.73.95]) by mx1.freebsd.org (Postfix) with ESMTP id 66A7A8FC08 for ; Tue, 10 Mar 2009 23:00:22 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from localhost (localhost [127.0.0.1]) by server.mypc.hu (Postfix) with ESMTP id 8DC2214D8765; Wed, 11 Mar 2009 00:00:14 +0100 (CET) X-Virus-Scanned: amavisd-new at t-hosting.hu Received: from server.mypc.hu ([127.0.0.1]) by localhost (server.mypc.hu [127.0.0.1]) (amavisd-new, port 10024) with LMTP id KgoOwai3I7Bb; Wed, 11 Mar 2009 00:00:14 +0100 (CET) Received: from [192.168.1.105] (catv-80-98-231-64.catv.broadband.hu [80.98.231.64]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by server.mypc.hu (Postfix) with ESMTPSA id E08B014D86CB; Wed, 11 Mar 2009 00:00:13 +0100 (CET) Message-ID: <49B6F0FB.5020307@FreeBSD.org> Date: Wed, 11 Mar 2009 00:00:11 +0100 From: =?ISO-8859-1?Q?G=E1bor_K=F6vesd=E1n?= User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: jimmy@mammothcheese.ca References: <49B6DC95.9070607@FreeBSD.org> <49B6E91A.4040604@mammothcheese.ca> In-Reply-To: <49B6E91A.4040604@mammothcheese.ca> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: freebsd-hackers@freebsd.org Subject: Re: fgetc doubts X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Mar 2009 23:00:23 -0000 James Bailie escribió: > fgetc() returns an int so that EOF may be distinguished from valid > return values. Valid values are 8-bit values. EOF is a 32-bit value. > > EOF is a 32-bit two's-complement -1 (0xffffffff), and -1 input is 8-bit > two's-complement -1 (0xff). When fgetc() casts this to an int, it > becomes 0x000000ff, or 255, and thus the two values may be distinguished > from each other. > > I haven't looked at your code, but you are probably comparing EOF with > the value returned by fgetc() after it has been cast to a char. EOF is > getting cast to a char implicitly in the comparison, so the comparison > becomes a comparison between 0xff and 0xff. You need to test the int > returned by fgetc() for EOF before assigning it to a char. Thanks, I've found all the pieces of the puzzle from the three comments and it works now. -- Gabor Kovesdan FreeBSD Volunteer EMAIL: gabor@FreeBSD.org .:|:. gabor@kovesdan.org WEB: http://people.FreeBSD.org/~gabor .:|:. http://kovesdan.org