September 2017
Intermediate to advanced
466 pages
9h 33m
English
The use of the fmt.Fprintf() function allows you to write formatted text to files in a way that is similar to the way the fmt.Printf() function works. Note that fmt.Fprintf() can write to any io.Writer interface and that our files will satisfy the io.Writer interface.
The Go code that illustrates the use of fmt.Fprintf() can be found in fmtF.go, which will be presented in three parts. The first part is the expected preamble:
package main import ( "fmt" "os" )
The second part has the following Go code:
func main() { if len(os.Args) != 2 { fmt.Println("Please provide a filename") os.Exit(1) } filename := os.Args[1] destination, err := os.Create(filename) if err != nil { fmt.Println("os.Create:", err) os.Exit(1) ...Read now
Unlock full access