#Why this scanf always trips the error after I type in the number

7 messages · Page 1 of 1 (latest)

wheat plume
#

In another program it even trips the error before I can type

ancient yew
#

try to see what the error is

#

print it out

wheat plume
# ancient yew print it out

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

fervent trellis
#
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?