I have a problem when parsing from a string to an integer that sometimes the string is being parsed to 0, despite not being 0.
Example:
What I would like to do first is parsing a string into three different integers. My code looks as follows:
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
line, _ := reader.ReadString('
')
splitted := strings.Split(line, " ")
N, _ := strconv.ParseInt(splitted[0], 0, 64) //Works as intended
P, _ := strconv.ParseInt(splitted[1], 0, 64) //Works as intended
Q, _ := strconv.ParseInt(splitted[2], 0, 64) //Does not work as intended
fmt.Print(N, P, Q) //For testing the parsing
}
If I input the string: "5 25 125", the output somehow becomes: 5 25 0.
This is the problem, sometimes the parsing parses the integer to the content of the string, which it should. But sometimes it parses the integer into a zero.
Why is this?