Golang fmt.Scan() function examples
package fmt
Scan scans text read from standard input, storing successive space-separated values into successive arguments. Newlines count as space. It returns the number of items successfully scanned. If that is less than the number of arguments, err will report why.
Golang fmt.Scan() function usage examples
Example 1 :
fmt.Printf("Enter 2 numbers> ")
fmt.Scan(&x)
fmt.Scan(&y)
fmt.Printf("Sending %d and %d\n", x, y)
Example 2 :
c := make(chan string)
go func() {
var o string
fmt.Scan(&o)
c <- o
}()
Example 3:
...
var (
readValue string
readSize int
)
readSize, err = fmt.Scan(&readValue)
if err != nil {
return
} else if readSize < 1 {
err = errors.New("Can't read input")
return
}
...
Reference :
Advertisement
Something interesting
Tutorials
+6k Golang : Function as an argument type example
+5.4k Golang : What is StructTag and how to get StructTag's value?
+7.1k Golang : Get environment variable
+13.9k Golang : How to check if a file is hidden?
+30.9k error: trying to remove "yum", which is protected
+9.7k Golang : Detect number of active displays and the display's resolution
+7.6k Android Studio : AlertDialog to get user attention example
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+12.6k Golang : Exit, terminating or aborting a program
+9.2k Golang : Write multiple lines or divide string into multiple lines
+14k Golang : Reverse IP address for reverse DNS lookup example
+12.2k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter