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
+14.5k Golang : How to check if your program is running in a terminal
+9.4k Android Studio : Indicate progression with ProgressBar example
+9.9k Golang : ffmpeg with os/exec.Command() returns non-zero status
+6.4k PHP : Proper way to get UTF-8 character or string length
+10.3k Golang : Convert file content to Hex
+8.9k Golang : Gaussian blur on image and camera video feed examples
+9.5k Golang : Get all countries currencies code in JSON format
+7.2k Golang : Null and nil value
+7.5k Golang : Process json data with Jason package
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+7.3k Golang : How to iterate a slice without using for loop?