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: Scanf %d%d fails when there is a newline in the middle of input #8236

Closed
gopherbot opened this issue Jun 19, 2014 · 1 comment
Closed

fmt: Scanf %d%d fails when there is a newline in the middle of input #8236

gopherbot opened this issue Jun 19, 2014 · 1 comment

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 19, 2014

by zr95.vip:

What does 'go version' print?

go version go1.3 windows/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. run the following Go program:

package main

import (
        "fmt"
)

func main() {
        var n, m int

        fmt.Scanf("%d%d", &n, &m);
        fmt.Println(n, m);
}

with input:

1
2

(two numbers, with a newline in the middle)

What happened?

The program prints:

1 0

What should have happened instead?

1 2

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

@ianlancetaylor ianlancetaylor commented Jun 19, 2014

Comment 1:

In order to match whitespace between two numbers, you need a space between the formats
in the scan string.  That is "%d %d".

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.