Golang fmt.Sscanln() function example

package fmt

Sscanln is similar to Sscan, but stops scanning at a newline and after the final item there must be a newline or EOF.

Golang fmt.Sscanln() function usage example

 package main

 import "fmt"

 func main() {

 answers := "1 0 \n 8"

 var a, b, c int

 // will stop scanning at \n
 fmt.Sscanln(answers, &a, &b, &c)
 fmt.Println(a, b, c)

 // for comparison
 answers = "1 0 8"
 fmt.Sscanln(answers, &a, &b, &c)
 fmt.Println(a, b, c)
 }

Output :

1 0 0 (c was not 'scanned')

1 0 8

Reference :

http://golang.org/pkg/fmt/#Sscanln

Advertisement