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
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+11.7k Golang : Secure file deletion with wipe example
+9.5k Golang : Convert(cast) string to int64
+26k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+15.6k Golang : Force download file example
+25.9k Golang : How to read integer value from standard input ?
+43.3k Golang : Convert []byte to image
+6.2k PHP : Get client IP address
+15.3k Golang : How to get Unix file descriptor for console and file
+10.8k Golang : Command line file upload program to server example
+12.5k Golang : HTTP response JSON encoded data