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

sort.Search GuessingGame documentation example does not work #43612

Open
bobjalex opened this issue Jan 9, 2021 · 5 comments
Open

sort.Search GuessingGame documentation example does not work #43612

bobjalex opened this issue Jan 9, 2021 · 5 comments

Comments

@bobjalex
Copy link

@bobjalex bobjalex commented Jan 9, 2021

What version of Go are you using (go version)?

$ go version
go version go1.15.6 windows/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=auto
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\bobja\AppData\Local\go-build
set GOENV=C:\Users\bobja\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\GoLib\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\GoLib
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\bobja\AppData\Local\Temp\go-build702450142=/tmp/go-build -gno-record-gcc-switches

What did you do?

What did you expect to see?

Expected to play the game.

What did you see instead?

Console prompting for an answer to its question asked 2 questions on same prompt line, making the game unusable.

Found and seemed to fix the problem in the example code: changed the fmt.Scanf("%s", &s) to fmt.Scanf("%s\n", &s).

@bobjalex
Copy link
Author

@bobjalex bobjalex commented Jan 9, 2021

Sorry, the "What did you do>" question seemed to be unanswered. Answer is: Copied and ran the GuessingGame example from the sort.Search documentation.

@robpike
Copy link
Contributor

@robpike robpike commented Jan 10, 2021

I tried this and it works fine as is, without the newline. We need more information.

@ALTree
Copy link
Member

@ALTree ALTree commented Jan 10, 2021

The example also work for me on Linux, but... #23562: Scanf works differently on Windows and Linux, and OP is using Windows. Possible root cause? The example was written and never tested on Windows?

@bobjalex
Copy link
Author

@bobjalex bobjalex commented Jan 11, 2021

@ALTree
Copy link
Member

@ALTree ALTree commented Jan 11, 2021

I can confirm the issue is reproducible on Windows (using cmd). So yeah I think #23562 is indeed the root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants