Created
January 8, 2011 08:21
-
-
Save swdunlop/770670 to your computer and use it in GitHub Desktop.
example of how to read an array in go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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]