#Why this scanf always trips the error after I type in the number
7 messages · Page 1 of 1 (latest)
The thing is when I print the error out, I got one time, nil, one time newline error, and one time error variable wasn’t assigned anything error
Once I’m able I’ll try and copy and paste them here
package main
import "fmt"
func main() {
var input int
for {
fmt.Printf("Type a number: ")
_, err := fmt.Scanf("%d", &input)
if err != nil {
fmt.Printf("[ERROR] Something went wrong, please input again: %v\n", err)
continue
} else {
fmt.Printf("Your number was: %d\n", input)
}
}
}
all normal, what you expect?