Golang fmt.Fscan() function examples
package flag
Fscan scans text read from r(1st parameter), 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.Fscan() function usage examples
Example 1:
func promptForString(field string, r io.Reader) string {
fmt.Printf("Please enter %s: ", field)
var result string
fmt.Fscan(r, &result)
return result
}
Example 2:
func KeysFromFile(name string) (string, string, error) {
file, err := os.Open(name)
if err != nil {
return "", "", err
}
defer file.Close()
var secret, access string
_, err = fmt.Fscan(file, &secret, &access) // <-- here
return secret, access, err
}
Reference :
Advertisement
Something interesting
Tutorials
+12.1k Golang : Save webcamera frames to video file
+10.6k Golang : Select region of interest with mouse click and crop from image
+7.1k Golang : Array mapping with Interface
+15.7k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+21.2k Golang : Clean up null characters from input data
+19.8k Golang : Append content to a file
+14.4k Android Studio : Use image as AlertDialog title with custom layout example
+20.7k Android Studio : AlertDialog and EditText to get user string input example
+11.2k Google Maps URL parameters configuration
+18.9k Golang : Read input from console line
+9.7k PHP : Get coordinates latitude/longitude from string
+5.3k Golang : How to deal with configuration data?