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
+19.6k Golang : Set or Add HTTP Request Headers
+8.2k Prevent Write failed: Broken pipe problem during ssh session with screen command
+13.1k Golang : List objects in AWS S3 bucket
+16.4k Golang : How to implement two-factor authentication?
+23.9k Golang : Fix type interface{} has no field or no methods and type assertions example
+7.4k Golang : Convert source code to assembly language
+6.1k Golang : Dealing with backquote
+14.1k Golang : Check if a file exist or not
+16k Golang : Get sub string example
+4.9k HTTP common errors and their meaning explained
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+8.8k Golang : HTTP Routing with Goji example