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 :
Advertisement
Something interesting
Tutorials
+12.3k Golang : Get month name from date example
+16.3k Golang : convert string or integer to big.Int type
+5.9k Golang : Denco multiplexer example
+29.2k Golang : missing Git command
+7k Golang : Takes a plural word and makes it singular
+9.5k Golang : Convert(cast) string to int64
+6.5k Golang : Combine slices of complex numbers and operation example
+5.7k Golang : Struct field tags and what is their purpose?
+6.8k Golang : Get expvar(export variables) to work with multiplexer
+29.5k Golang : Saving(serializing) and reading file with GOB
+13.2k Golang : Convert(cast) int to int64
+6.4k PHP : Proper way to get UTF-8 character or string length