Date: Wed, 15 Jan 1997 12:10:45 -0800 (PST) From: John-Mark Gurney <jmg@nike.efn.org> To: scrutchfield@ifusion.com Cc: freebsd-gnats-submit@freebsd.org, GNATS Management <gnats@freefall.freebsd.org>, freebsd-bugs@freefall.freebsd.org Subject: Re: bin/2502: Unable to sscanf first integer value. Message-ID: <Pine.NEB.3.95.970115120659.326I-100000@hydrogen.nike.efn.org> In-Reply-To: <199701151538.HAA07065@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h> > #include <string.h> > #include <stdlib.h> > > 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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.95.970115120659.326I-100000>