First of all, I am a newbie to Go programming. I have a simple Golang program which is giving the correct output in Linux environment but not in my Windows 10 PC.
The code is as follows:
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text: ")
text, _ := reader.ReadString('
')
tarr := strings.Split(strings.Trim(text, "
"), " ")
for i := 0; i < len(tarr); i++ {
num, _ := strconv.ParseInt(tarr[i], 10, 32)
fmt.Println(num)
}
fmt.Println(tarr)
reader.ReadString('
')
}
If I enter 1 2 3 as input from the terminal, I am getting the following output in Windows 10 (go version go1.12.5 windows/amd64):
1
2
0
]1 2 3
I am getting the following output in Linux Elementary OS (go version go1.12.5 linux/amd64)
1
2
3
[1 2 3]
Can anyone explain why this is happening?