code.go 535 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "log"
  6. "os"
  7. )
  8. func readInput(file *os.File) []string {
  9. scanner := bufio.NewScanner(file)
  10. var maze []string
  11. for scanner.Scan() {
  12. line := scanner.Text()
  13. if line == "" {
  14. continue
  15. }
  16. maze = append(maze, line)
  17. }
  18. return maze
  19. }
  20. func main() {
  21. if len(os.Args) < 2 {
  22. log.Fatal("You need to specify a file!")
  23. }
  24. filePath := os.Args[1]
  25. file, err := os.Open(filePath)
  26. if err != nil {
  27. log.Fatalf("Failed to open %s!\n", filePath)
  28. }
  29. maze := readInput(file)
  30. fmt.Println(maze)
  31. }