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
+14.6k Golang : Convert(cast) int to float example
+11.7k Golang : Gorilla web tool kit secure cookie example
+20.2k Golang : Count number of digits from given integer value
+5.3k Swift : Convert string array to array example
+22.2k Golang : Securing password with salt
+11k How to test Facebook App on localhost ?
+4.9k Python : Find out the variable type and determine the type with simple test
+10.2k Golang : Random Rune generator
+10.3k Golang : Convert file unix timestamp to UTC time example
+6.2k Linux/Unix : Commands that you need to be careful about
+5.4k Golang : fmt.Println prints out empty data from struct