Date: Wed, 15 Jan 1997 12:20:03 -0800 (PST) From: John-Mark Gurney <jmg@nike.efn.org> To: freebsd-bugs Subject: Re: bin/2502: Unable to sscanf first integer value. Message-ID: <199701152020.MAA22680@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/2502; it has been noted by GNATS.
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.
Date: Wed, 15 Jan 1997 12:10:45 -0800 (PST)
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?199701152020.MAA22680>
