mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:55:35 +08:00
update book code
This commit is contained in:
24
eBook/examples/chapter_12/readinput1.go
Normal file
24
eBook/examples/chapter_12/readinput1.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// read input from the console:
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
firstName, lastName, s string
|
||||
i int
|
||||
f float32
|
||||
input = "56.12 / 5212 / Go"
|
||||
format = "%f / %d / %s"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Please enter your full name: ")
|
||||
fmt.Scanln(&firstName, &lastName)
|
||||
// fmt.Scanf("%s %s", &firstName, &lastName)
|
||||
fmt.Printf("Hi %s %s!\n", firstName, lastName) // Hi Chris Naegels
|
||||
|
||||
fmt.Sscanf(input, format, &f, &i, &s)
|
||||
fmt.Println("From the string we read: ", f, i, s) // From the string we read: 56.12 5212 Go
|
||||
}
|
Reference in New Issue
Block a user