1.go (515B) [raw]
1 package main 2 3 import ( 4 "bufio" 5 "fmt" 6 "log" 7 "os" 8 "strings" 9 ) 10 11 func main() { 12 fname := "input.txt" 13 if len(os.Args) > 1 { 14 fname = os.Args[1] 15 } 16 f, err := os.Open(fname) 17 if err != nil { 18 log.Fatal(err) 19 } 20 defer f.Close() 21 22 grid := [][]string{} 23 scanner := bufio.NewScanner(f) 24 for scanner.Scan() { 25 line := scanner.Text() 26 row := strings.Split(line, "") 27 fmt.Println(row) 28 grid = append(grid, [][]string{row}...) 29 } 30 fmt.Println(grid[0][0]) 31 32 if err := scanner.Err(); err != nil { 33 log.Fatal(err) 34 } 35 }