Question:I have this piece of go code, mostly taken from here:
fmt.Scanf("%s", &roleName)returns after reading the first whitespace character after the token.
The line terminator on Windows is
\r\n. The fmt.Scanf call returns after reading the
\nremains in stdin. The later call to
scanner.Scan()reads the remaining
\nin stdin and returns immediately.
The line terminator on other systems is
\n. The call fmt.Scanf returns after reading the entire line terminator. The call to
scanner.Scan()waits for the user to type another line terminator.
One fix is to use the scanner for all input:
If you have better answer, please add a comment about this, thank you!