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

Comments

@gopherbot
Copy link

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

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
Development

No branches or pull requests

2 participants