delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/01/11/14:05:01

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <3C3F3735.73DF687F@cfa.harvard.edu>
Date: Fri, 11 Jan 2002 14:04:22 -0500
From: William Joye <wjoye AT cfa DOT harvard DOT edu>
X-Mailer: Mozilla 4.76 [en] (X11; U; SunOS 5.8 sun4u)
X-Accept-Language: en
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: 1.3.6: sscanf bug (error with %n)

There seems to be a bug with trailing spaces and %n with sscanf strings.
In particular, %n fails if it is the last item in the format string and
it is preceeded with a space.

Here is some sample code:

#include <stdio.h>

main()
{
  char foo[] = " name 1111.1 ";

  char bar[8];
  float ff;
  int nc;
  int r;

  nc = 0;
  r = sscanf(foo, " %s %f %n", bar, &ff, &nc);
  printf ("  space got:%d count:%d\n", r, nc);

  nc = 0;
  r = sscanf(foo, " %s %f%n", bar, &ff, &nc);
  printf ("nospace got:%d count:%d\n", r, nc);
}

cygwin 1.3.6 outputs:

  space got:2 count:0
nospace got:2 count:12

The correct output should be:

  space got:2 count:13
nospace got:2 count:12

--
Bill Joye
wjoye AT cfa DOT harvard DOT edu
Smithsonian Astrophysical Observatory
Harvard-Smithsonian Center for Astrophysics




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019