From owner-freebsd-questions@FreeBSD.ORG Wed Oct 24 02:28:36 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BFFEC16A41B for ; Wed, 24 Oct 2007 02:28:36 +0000 (UTC) (envelope-from cpghost@cordula.ws) Received: from fw.farid-hajji.net (fw.farid-hajji.net [213.146.115.42]) by mx1.freebsd.org (Postfix) with ESMTP id 4939513C4A7 for ; Wed, 24 Oct 2007 02:28:36 +0000 (UTC) (envelope-from cpghost@cordula.ws) Received: from epia-2.farid-hajji.net (epia-2 [192.168.254.11]) by fw.farid-hajji.net (Postfix) with ESMTP id 9622AE04B9; Wed, 24 Oct 2007 04:28:30 +0200 (CEST) Date: Wed, 24 Oct 2007 04:28:28 +0200 From: cpghost To: Harald Schmalzbauer Message-ID: <20071024042828.6194532e@epia-2.farid-hajji.net> In-Reply-To: <200710232324.09851.h.schmalzbauer@omnisec.de> References: <200710232044.53240.h.schmalzbauer@omnisec.de> <20071023220134.3abd635e@epia-2.farid-hajji.net> <20071023162454.93851854.wmoran@potentialtech.com> <200710232324.09851.h.schmalzbauer@omnisec.de> Organization: Cordula's Web X-Mailer: Claws Mail 3.0.1 (GTK+ 2.10.14; i386-portbld-freebsd6.2) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-questions@freebsd.org Subject: Re: Mentor for C self study wanted X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2007 02:28:36 -0000 On Tue, 23 Oct 2007 23:24:09 +0200 Harald Schmalzbauer wrote: > #include >=20 > void main() > { > short nnote; >=20 > // Numerischen Notenwert einlesen > printf("Bitte numerischen Schulnotenwert eingeben: "); > scanf("%d",&nnote); >=20 > switch (nnote) > { > case 1: printf("Die Note %d entspricht sehr gut.",nnote); > break; > case 2: printf("Die Note %d entspricht gut.",nnote); > break; > case 3: printf("Die Note %d entspricht befriedigend.",nnote); > break; > case 4: printf("Die Note %d entspricht ausreichend.",nnote); > break; > case 5: printf("Die Note %d entspricht mangelhaft.",nnote); > break; > case 6: printf("Die Note %d entspricht ungen=FCgend.",nnote); > break; > default: printf("%d ist keine zul=E4ssige Schulnote!"); ^^^^^ ^^^^^ No matching int for "%d" here. It'll print garbage. Change to: default: printf("%hd ist keine...!", nnote); ^^^^^^^^ > } > printf("\n"); > } >=20 > P.S.: > I found that declaring nnote as int soleves my problem, but I > couldn=C4t understand why. > Another one was the result of default: nnote was -1077942208 instead > of 9 for example. The reason for this is that the number of arguments after printf's format string MUST match the number of %-place holders (unless you're using exotic stuff like %n, of course). If printf misses some arguments, it will fetch them from a place that is implementation dependant (and that almost always means: you'll get garbage). Sorry for overlooking your second question... ;) -cpghost. --=20 Cordula's Web. http://www.cordula.ws/