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
+7.8k Golang : Regular Expression find string example
+5.9k AWS S3 : Prevent Hotlinking policy
+41.9k Golang : How do I convert int to uint8?
+9.1k Golang : Gonum standard normal random numbers example
+4.5k Java : Generate multiplication table example
+7.9k Javascript : How to check a browser's Do Not Track status?
+6.3k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+13.9k Golang : Get dimension(width and height) of image file
+12.9k Python : Convert IPv6 address to decimal and back to IPv6
+10.1k Golang : Edge detection with Sobel method
+6.9k Golang : Normalize email to prevent multiple signups example
+6.7k Golang : When to use make or new?