delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/25/23:44:44

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199605260317.AA134410644@relay1.geis.com>
Date: Sun, 26 May 96 03:20:00 UTC 0000
To: fredex AT fcshome DOT stoneham DOT ma DOT us
Cc: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: djgpp 2.0 fscanf bug??

Reply to message 6692115    from FREDEX AT FCSHOM on 05/25/96 10:01AM


>It seems to me that fscanf is not
>failing (and therefore returning <= 0) when input does not match the
>format, which is what I think it SHOULD be doing. In the particular
>example, there are a series of lines from which four tokens are read
>"%d%s%s%s", followed by a line with only one token. Other fscanf
>implementations I've worked with return <= 0 when they hit this line,
>but the one in djgpp seems to return 4, with incorrect result
>assignments.  OTOH, I may be wrong and it may be something more
>subtle than that.

Woops!  At first I thought you had an ANSI compliance problem, but
then I took a closer look at your code...

>	while ((n = fscanf (infile, "%d%s%s%s", &fldLen, typ, ro, nr)) > 0)

--- from data file ---
[...]
>15 NM OPT NO_RPT   	/* 13 Sequence Number           */
>180 ST OPT NO_RPT  	/* 14 Continuation Pointer      */
>MSH
 ^^^

On that last line you are trying to read a string into an integer, so fscanf()
fails and returns zero!  The while loop terminates _before_ displaying
the data, and displays the file position _before_ the last read.  The bug
is in yer program.  :)

>BTW, I've not yet joined the list, so I'd appreciate it if you could
>reply direct to me.

Hey, go ahead and join!  We're a real friendly bunch and the traffic
is only 20-30 messages a day on average.  Or just visit the newsgroup
comp.os.msdos.djgpp, which is a mirror to/from the mailing list.

hth,

John

- Raw text -


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