I'm new programming with Go. I've been writing this little program that uses structures. It's a structure called user, which has as values, first name, last name and age. The problem lies when entering data, more specifically when it comes to entering the last name, this error happens: a screenshot of the error
You can see from the image that when you introduces data in the name field, ignores last name field, and jumps to age.
Having knowledge in C, this error happens when the buffer has not been flushed. (but C is a different language from Go)
As I know, Go stdin read is unbuffered. So how would you solve this problem?
Here's the code:
package main
import "fmt"
type user struct {
name, surnm string
age int
}
func main() {
n := new(user)
fmt.Print("Name? ")
fmt.Scanf("%s", &n.name)
fmt.Print("Last name? ")
fmt.Scanf("%s", &n.surnm)
fmt.Print("Age? ")
fmt.Scanf("%d", &n.age)
fmt.Println(n.name)
fmt.Println(n.surnm)
fmt.Println(n.age)
}
Sorry if my question is a little bit stupid, but how I said, I am new at Go.