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
+10.1k Golang : Compare files modify date example
+12.8k Golang : Convert int(year) to time.Time type
+8.8k Golang : Take screen shot of browser with JQuery example
+21.5k Golang : How to read float value from standard input ?
+6.7k Golang : Output or print out JSON stream/encoded data
+21.8k Golang : Convert string slice to struct and access with reflect example
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+26.7k Golang : How to check if a connection to database is still alive ?
+14k Golang : Compress and decompress file with compress/flate example
+5.4k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+21.2k Golang : Clean up null characters from input data
+19.2k Golang : Check whether a network interface is up on your machine