Skip to content

Instantly share code, notes, and snippets.

@swdunlop
Created January 8, 2011 08:21
Show Gist options
  • Save swdunlop/770670 to your computer and use it in GitHub Desktop.
Save swdunlop/770670 to your computer and use it in GitHub Desktop.
example of how to read an array in go
package main
import "fmt"
type row [3]int
type grid [3]row
func main() {
var g grid
for _, r := range g {
for i := 0; i < len( r ); i ++ {
_, err := fmt.Scan( &r[i] ); if err != nil {
fmt.Print( err )
}
}
fmt.Println( r )
}
}
@swdunlop
Copy link
Author

swdunlop commented Jan 8, 2011

Example Use:
$ cat <<EOF | (6g array.go && 6l array.6 && ./6.out)
. 1 2 3
. 4 5 6
. 7 8 9
. EOF
[1 2 3]
[4 5 6]
[7 8 9]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment