Loop skipping over input in golang

Viewed 243

I'm trying to check if an input is blank and ask for input again using a for loop, but the program is just repeatedly going over the loop without stopping to wait for input and outputting the print statement within it 100 times, what am I doing wrong?

var input string

    for len(input) == 0 {

        fmt.Println("What would you like to write in the journal?")

        input = usr.GetInput()

    }

GetInput uses bufio.NewScanner and returns scanner.Text, but even when I try Scanln, the error still occurs.

Edit:

As requested here is GetInput

func GetInput() string {

    scanner := bufio.NewScanner(os.Stdin)

    return scanner.Text()

}
1 Answers

I managed to get the program to work by trying it again with fmt.Scanln(), and this time including a pointer to the variable with an asterisk instead of just putting the variable in Scanln.

Related