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

Failed to run the same program with CMD terminal while with GolLand it works fine. #33827

Closed
shipherd opened this issue Aug 25, 2019 · 2 comments

Comments

@shipherd
Copy link

shipherd commented Aug 25, 2019

Environment: Go version: go1.12.9 windows/amd64, Windows 10 1903, GoLand Version: 2019.2

Code File:
c.txt

This program gets input from stdin.
The first input indicates how many groups of numbers.
The second input is also a number, which means how many numbers in the first group.
The third input can be a string of numbers, separated by space. These are all the numbers in the first group.
By repeating the second and third steps, we can input multi-groups of numbers.
The output is the square sums (all the negative numbers are ignored) of the numbers in each group.

e.g.
inputs:
2 //2 Groups
2 //2 Numbers in the first group
1 2 //First group
1 //1 Number in the second group
4// Second Group
outputs:
5 //11+22
16//4*4

Issue:

Here is the intended result from GoLand:
inputs:
2
1
-1
1
1
outputs:
0
1

But from the CMD terminal:

C:\Users\Vic\Desktop\challenge>go run c.go
2
1
-1
panic: runtime error: index out of range

goroutine 1 [running]:
main.IterElements(0xfffffffffffffffe, 0xc0000402b0, 0x0, 0x0, 0xc00005c420)
C:/Users/Vic/Desktop/challenge/c.go:22 +0x13a
main.IterElements(0xffffffffffffffff, 0xc0000402b0, 0x1, 0x1, 0x0)
C:/Users/Vic/Desktop/challenge/c.go:33 +0x105
main.iterGroups(0x1)
C:/Users/Vic/Desktop/challenge/c.go:45 +0x11e
main.iterGroups(0x2)
C:/Users/Vic/Desktop/challenge/c.go:49 +0x163
main.main()
C:/Users/Vic/Desktop/challenge/c.go:67 +0xba
exit status 2

Not sure what is wrong here, any help?

Thank you!

@bcmills
Copy link
Contributor

bcmills commented Aug 26, 2019

Your readLine function buffers an unspecified quantity of input from os.Stdin, then returns the first line of that input — discarding the remainder. It most likely displays different results in the two environments due to a different pattern of writes to stdin.

@bcmills
Copy link
Contributor

bcmills commented Aug 26, 2019

This issue seems to be a question about how to use Go, rather than a feature request or defect report about the Go language and/or toolchain.

We have decided that our experiment to allow questions on the issue tracker has not had the outcome we desired, so I am closing this issue. I'm sorry that we can't answer your question here.

There are many other methods to get help if you're still looking for answers:

Thanks

@bcmills bcmills closed this as completed Aug 26, 2019
@golang golang locked and limited conversation to collaborators Aug 25, 2020
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