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: How can I empty input stream? The fmt.Scanf in a main cannot use more than 2 times, the second will appear to skip a need for input. #13608

Closed
CodyGuo opened this issue Dec 14, 2015 · 4 comments

Comments

@CodyGuo
Copy link

CodyGuo commented Dec 14, 2015

How can I empty input stream?

package main

import (
"fmt"
)

func main() {
var a int
var f float32
var str string

fmt.Print("Please input : ")
fmt.Scanf("%d %f %s", &a, &f, &str)
fmt.Println("Output: ", a, f, str)

fmt.Println("----------------------------")

var sIP, sMac string
fmt.Print("Please input: ")
fmt.Scanf("%s %s", &sIP, &sMac)

fmt.Println("Output: ", sIP, sMac)

}

OUTPUT:
Please input : 1 3.24 hello

Output: 1 3.24 hello

Please input: Output:

@davecheney
Copy link
Contributor

Duplicate of #13607.

Please do not ask questions on the issue tracker. The issue tracker is only for bugs.

Please see https://github.com/golang/go/wiki/Questions

@CodyGuo
Copy link
Author

CodyGuo commented Dec 14, 2015

I'm sorry, I don't have access to mailing lists and BBS address.

@davecheney
Copy link
Contributor

@CodyGuo I'm sorry to hear that. We cannot have a discussion on the issue tracker. I have heard there is a cn language mailing list, perhaps they can help. /cc @minux

@CodyGuo
Copy link
Author

CodyGuo commented Dec 14, 2015

Thank you, I found the solution.
/ / initialize the stdin
os. Stdin = os. NewFile (uintptr (syscall. Stdin), "/ dev/stdin")

@golang golang locked and limited conversation to collaborators Dec 14, 2016
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