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

fmt.Fscanf bug? #954

Closed
gopherbot opened this issue Jul 25, 2010 · 2 comments
Closed

fmt.Fscanf bug? #954

gopherbot opened this issue Jul 25, 2010 · 2 comments

Comments

@gopherbot
Copy link

by bcfabien:

What steps will reproduce the problem?

fmt.Fscanf appears to produce incorrect results when a newline is 
preceded by a space.

package main
import "fmt"
import "strings"
func main() {
  var z float64
  fmt.Printf("unexpected result\n")
  in := strings.NewReader(" 1.1 1.2 1.3 \n 2.4 2.5 2.6 \n 3.7 3.8 3.9 ")
  for i := 0; i < 9; i++ {
      fmt.Fscanf(in, "%e", &z) // throws "unexpected newline"
      fmt.Printf(" %g ", z)
  }
  fmt.Printf("\n")
  fmt.Printf("expected result\n")
  in = strings.NewReader(" 1.1 1.2 1.3\n 2.4 2.5 2.6\n 3.7 3.8 3.9")
  for i := 0; i < 9; i++ {
      fmt.Fscanf(in, "%e", &z)
      fmt.Printf(" %g ", z)
  }
  fmt.Printf("\n")
}

What is the expected output?

expected result
 1.1  1.2  1.3  2.4  2.5  2.6  3.7  3.8  3.9

What do you see instead?

unexpected result
 1.1  1.2  1.3  1.3  2.4  2.5  2.6  2.6  3.7 
 
What is your $GOOS?  $GOARCH?

GOARCH=amd64
GOOS=darwin

Which revision are you using?  (hg identify)

localhost:go $ hg summary
parent: 5812:5992bf56aa72 release.2010-07-14 release
 release.2010-07-14
branch: default
commit: 1 unknown (clean)
update: 54 new changesets (update)

Please provide any additional information below.
@adg
Copy link
Contributor

adg commented Jul 26, 2010

Comment 1:

Owner changed to r...@golang.org.

Status changed to Accepted.

@robpike
Copy link
Contributor

robpike commented Jul 26, 2010

Comment 2:

This issue was closed by revision a59e113.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc unassigned robpike Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants