# bug #63353: Error in fscanf when maximum field width is specified and '%f' conversion used

 Submitter: José Luis García Pallero Submitted: Sat 12 Nov 2022 05:17:04 PM UTC Category: Octave Function Severity: 3 - Normal Priority: 5 - Normal Item Group: Incorrect Result Status: Confirmed Assigned to: None Originator Name: José Luis García Pallero Open/Closed:  * Open Release:  * other Operating System:  * Any Fixed Release: None Planned Release: None
* Mandatory Fields

Add a New Comment Rich Markup

## Discussion

Tue 15 Nov 2022 04:40:24 PM UTC, comment #2:

If I had to take a guess, I think Matlab divides the input stream based on the field width and then applies the conversion to each chunk of input.  Octave, however, seems to apply the conversion to the input and then move to whatever remains of the input stream.

Matlab behavior:

v = sscanf ('1.234.567', '%3f')
v =
1.2
34.0
567

Octave behavior:

v = sscanf ('1.234.567', '%3f')
v =
1.234
0.567

Rik <rik5>
Tue 15 Nov 2022 04:31:09 PM UTC, comment #1:

Confirmed.  The behavior is also dependent on the type of the conversion.  If the conversion is to an integer type then the function behaves as expected.  For example,

[v,n] = sscanf (a, '%3d')
v =

123
456
7

n = 3

It is only when a floating point type such as '%f', '%e', '%g' is used that there is a problem.

Rik <rik5>
Sat 12 Nov 2022 05:17:04 PM UTC, original submission:

Octave documentation states the maximum field width option in the input conversion syntax for fscanf and sscanf functions (https://docs.octave.org/latest/Input-Conversion-Syntax.html). But this example works in Matlab:

a = '1234567';
[val,n] = sscanf(a,'%3f',[1 Inf])
val =
123   456     7
n =
3

but not in Octave:

a = '1234567';
[val,n] = sscanf(a,'%3f',[1 Inf])
val = 1234567
n = 1

José Luis García Pallero <jgpallero>

## Attached Files

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

Attach Files:

Comment:

No files currently attached

## Dependencies

Depends on the following items: None found

Items that depend on this one: None found

Carbon-Copy List
• -email is unavailable- added by rik5 (Posted a comment)
• -email is unavailable- added by jgpallero (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 project members can vote.