From owner-freebsd-bugs Wed Jan 15 12:12:34 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id MAA21005 for bugs-outgoing; Wed, 15 Jan 1997 12:12:34 -0800 (PST) Received: from hydrogen.nike.efn.org (resnet.uoregon.edu [128.223.170.28]) by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id MAA20905; Wed, 15 Jan 1997 12:11:32 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by hydrogen.nike.efn.org (8.8.4/8.8.4) with SMTP id MAA02241; Wed, 15 Jan 1997 12:10:49 -0800 (PST) Date: Wed, 15 Jan 1997 12:10:45 -0800 (PST) From: John-Mark Gurney Reply-To: John-Mark Gurney To: scrutchfield@ifusion.com cc: freebsd-gnats-submit@freebsd.org, GNATS Management , freebsd-bugs@freefall.freebsd.org Subject: Re: bin/2502: Unable to sscanf first integer value. In-Reply-To: <199701151538.HAA07065@freefall.freebsd.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk On Wed, 15 Jan 1997 scrutchfield@ifusion.com wrote: > >Synopsis: Unable to sscanf first integer value. [...] > >Description: > I am unable to sscanf correctly 2 integers from a string. A Sample > program that recreates the problem is shown below. This is a problem > in both libc and libc_r. > > #include > #include > #include > > main() > { > char *tmp = "999 12346"; > char *ptr; > unsigned short x; > unsigned short y; > unsigned short z; you need these to be int's, not short... if you want a short use %hd instead.. > unsigned int a; > int result; > > result = sscanf ( tmp, "%d %d", &x, &y ); > z = strtol ( tmp, &ptr, 0 ); > a = atoi ( tmp ); > (void)fprintf ( stderr, "x(%d)y(%d)z(%d)a(%d)\n", x, y, z, a ); > exit ( 0 ); > } > > >How-To-Repeat: > Run the above program. > >Fix: use scanf like it was designed to... if you need help man 3 scanf should contain the missing info... hope this helps... ttyl.. John-Mark gurney_j@efn.org http://resnet.uoregon.edu/~gurney_j/ Modem/FAX: (541) 683-6954 (FreeBSD Box) Live in Peace, destroy Micro$oft, support free software, run FreeBSD (unix)