Golang fmt.Fscanf() function examples
package fmt
Fscanf scans text read from r(1st parameter), storing successive space-separated values into successive arguments as determined by the format. It returns the number of items successfully parsed.
Golang fmt.Fscanf() function usage examples
Example 1:
func readCon(name string) (string, error) {
var val string
in, err := os.Open(name)
if err != nil {
return "", err
}
defer in.Close()
_, err = fmt.Fscanf(in, "%s", &val) // <-- here
return val, err
}
Example 2 :
team := os.Args[0]
var answer string
fmt.Fprintf(os.Stdout, `Are you sure you want to remove team "%s"? (y/n) `, team)
fmt.Fscanf(os.Stdin, "%s", &answer) // <-- here
if answer != "y" {
fmt.Fprintln(os.Stdout, "Abort.")
return nil
}
Reference :
Advertisement
Something interesting
Tutorials
+9.6k Golang : Quadratic example
+6.8k Swift : substringWithRange() function example
+9k Golang : Get SPF and DMARC from email headers to fight spam
+21.2k Golang : How to force compile or remove object files first before rebuild?
+35.3k Golang : Strip slashes from string example
+17.5k Golang : Clone with pointer and modify value
+12.4k Golang : Encrypt and decrypt data with x509 crypto
+21.1k Golang : For loop continue,break and range
+10k CodeIgniter : Load different view for mobile devices
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference