bugGNU Octave - Bugs: bug #54892, sscanf %1c returns more than one...

 
 

bug #54892: sscanf %1c returns more than one character

Submitter:  None
Submitted:  Wed 24 Oct 2018 04:44:29 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Uli Wortmann Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.4.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 29 Oct 2018 07:36:40 PM UTC, comment #4: 

Posted to the mailing list:

Thanks for the explanation, that clarifies it. Note however that while sscanf documentation indeed shows the third argument and states that unless set, it will be assumed Inf., there is no mention of the functional relationship between the function call and the value of size.

Adding a few words will greatly improve clariity

https://octave.org/doc/v4.0.0/Formatted-Input.html

Cheers

Uli

John W. Eaton <jwe>
Group administrator
Sun 28 Oct 2018 09:23:08 PM UTC, comment #3: 

There are definite problems with the documentation.
It needs rewrite and some examples.

Michael Godfrey <godfrey>
Group Member
Sun 28 Oct 2018 07:59:18 PM UTC, comment #2: 

I'd say this is a problem in the documentation. The behaviour expected by the initial comment is achieved when you invoke sscanf with "C". So this is the "second form" according to https://octave.org/doc/v4.4.1/Formatted-Input.html. But even there it says that each conversion specifier corresponds to a single scalar return value. In https://octave.org/doc/v4.4.1/Input-Conversion-Syntax.html the "maximum field width" is defined, and explicitly referenced under the documentation of the "%c" conversion specification https://octave.org/doc/v4.4.1/Table-of-Input-Conversions.html. But seemingly this is considered only with "C", which however is indeed not mentioned there.

Michael Leitner <mleitner>
Fri 26 Oct 2018 01:34:04 AM UTC, comment #1: 

This is expected.  See the documentation for sscanf.  The third argument is the number of times the pattern should be read.  It defaults to Inf, in other words, as many as possible.  You can check this by using the second output argument which returns how many pattern was applied.


octave:11> [h,n] =sscanf(g,"%1c")
h = Hello World
n =  11


Here's an example of reading a single character with sscanf.


octave:13> [h, n] = sscanf (g, "%1c", 1)
h = H
n =  1




Rik <rik5>
Group administrator
Wed 24 Oct 2018 04:44:29 PM UTC, original submission:  

If I use
g="Hello World"

and then
 
h=sscanf(g,"%1c")

h equals "Hello World"

The expected result would "H"


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by mleitner (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-10-26 rik5 StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code