-
Notifications
You must be signed in to change notification settings - Fork 21
/
prompt.go
33 lines (28 loc) · 701 Bytes
/
prompt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"bufio"
"fmt"
"os"
)
// Prompt user for input and repeat it back
func main() {
// Here is one way to read
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text: ")
text, _ := reader.ReadString('\n')
fmt.Println("You entered:", text)
// Read some more with the same reader
fmt.Print("Enter more text: ")
textmore, _ := reader.ReadString('\n')
fmt.Println("You entered:", textmore)
// Here is another way that doesn't work
// if there are spaces in what you enter.
fmt.Print("Enter even more text: ")
text2 := ""
fmt.Scanln(&text2)
fmt.Println("You entered:", text2)
// Not sure about this one
//ln := ""
//fmt.Sscanln("%v", ln)
//fmt.Println(ln)
}