// Homework 31, problem 1: A shopping list file. // // Write writeList, which creates the file name and writes one item per line, // numbered from 1, like "1. rice". Use os.Create, a bufio.Writer and // fmt.Fprintf, and do not forget Flush. main is finished: it writes the list to // shopping.txt, then reads the file back and prints it. The file is created in // the folder you run the program from. // // You will need to add "bufio" to the imports. // // Run with: go run exercises/31/homework/01-shopping-list.go package main import ( "fmt" "os" ) func writeList(name string, items []string) error { // TODO: create the file and write the numbered items. fmt.Println("TODO: writeList does not write yet") return os.WriteFile(name, []byte{}, 0644) } func main() { items := []string{"rice", "eggs", "tea", "bananas"} err := writeList("shopping.txt", items) if err != nil { fmt.Println("Error:", err) return } data, err := os.ReadFile("shopping.txt") if err != nil { fmt.Println("Error:", err) return } fmt.Print(string(data)) }