readinput1.go 597 B

123456789101112131415161718192021222324
  1. // read input from the console:
  2. package main
  3. import (
  4. "fmt"
  5. )
  6. var (
  7. firstName, lastName, s string
  8. i int
  9. f float32
  10. input = "56.12 / 5212 / Go"
  11. format = "%f / %d / %s"
  12. )
  13. func main() {
  14. fmt.Println("Please enter your full name: ")
  15. fmt.Scanln(&firstName, &lastName)
  16. // fmt.Scanf("%s %s", &firstName, &lastName)
  17. fmt.Printf("Hi %s %s!\n", firstName, lastName) // Hi Chris Naegels
  18. fmt.Sscanf(input, format, &f, &i, &s)
  19. fmt.Println("From the string we read: ", f, i, s) // From the string we read: 56.12 5212 Go
  20. }