octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #46493] Incorrect result from fscanf and scanf


From: Rik
Subject: [Octave-bug-tracker] [bug #46493] Incorrect result from fscanf and scanf with %i format
Date: Mon, 23 Nov 2015 00:49:05 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0

Update of bug #46493 (project octave):

                  Status:                    None => Confirmed              
        Operating System:       Microsoft Windows => Any                    
                 Summary: Incorrect result from fscanf and scanf => Incorrect
result from fscanf and scanf with %i format

    _______________________________________________________

Follow-up Comment #3:

Confirmed using Doug's simplified example from comment #2.

As a simple workaround, if you know that the numbers are in decimal format
then you can use either %u for unsigned or %d for optionally signed integers. 
The following format works


frm = '"%d" ,"%i","%i","%i","%i","%i"\n';
sscanf ('"08"', frm)
ans =  8


The trouble seems to be that %i must recognize decimal, octal, and
hexadecimal.  In this case, the first character of the number is a '0' which
seems to trigger the octal conversion format.  But there is no valid octal
number for 8 and 9 so it returns '0' for that conversion.

On the other hand, anything you do which breaks the recognition of the number
as octal will cause it to work.  For example,


sscanf ('"+08"', frm)
ans =  8
sscanf ('"-08"', frm)
ans = -8


It would be interesting to know if Matlab gets this right.  If anyone has
access, could they run the following two tests?


sscanf ('"09"', '"%i"')
sscanf ('"079"', '"%i"')




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?46493>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]