Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"%0c" format of scanf must not consume any character in the input #6531

Closed
vicuna opened this issue Sep 1, 2014 · 1 comment
Closed

"%0c" format of scanf must not consume any character in the input #6531

vicuna opened this issue Sep 1, 2014 · 1 comment
Assignees
Milestone

Comments

@vicuna
Copy link

vicuna commented Sep 1, 2014

Original bug ID: 6531
Reporter: cfranch
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2016-12-07T10:34:50Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 4.02.0+beta1 / +rc1
Target version: 4.02.2+dev / +rc1
Category: standard library
Monitored by: @hcarty

Bug description

Hi,
it looks like that module Scanf is no more compliant to its documentation:

[c]: reads a single character. To test the current input character without reading it, specify a null field width, i.e. use specification [%0c].

I did a test with the recent version of OCaml and I got the following wrong result.peek char of scanf consumes the char

    OCaml version 4.02.0

let ib = Scanf.Scanning.from_string "foo";;

val ib : Scanf.Scanning.in_channel =

Scanf.bscanf ib "%0c" (fun c -> c);;

  • : char = 'f'

Scanf.bscanf ib "%0c" (fun c -> c);;

  • : char = 'o'

Scanf.bscanf ib "%0c" (fun c -> c);;

  • : char = 'o'

Scanf.bscanf ib "%0c" (fun c -> c);;

Exception: End_of_file.

The correct result is 'f' for every call to function 'bscanf "%0c"'.

Thank you very much.

@vicuna
Copy link
Author

vicuna commented Sep 21, 2014

Comment author: @gasche

Fixed in branch 4.02.

@vicuna vicuna closed this as completed Dec 7, 2016
@vicuna vicuna added the stdlib label Mar 14, 2019
@vicuna vicuna added this to the 4.02.2 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants