Skip to content

Instantly share code, notes, and snippets.

@johnwesonga
Created December 14, 2016 18:38
Show Gist options
  • Save johnwesonga/1b93f7d09e6aa02b6844bef0596b6fce to your computer and use it in GitHub Desktop.
Save johnwesonga/1b93f7d09e6aa02b6844bef0596b6fce to your computer and use it in GitHub Desktop.
Read ints with whitespaces from stdin
package main
import "fmt"
func main() {
fmt.Println(`Enter the number of integers`)
var n int
if m, err := fmt.Scan(&n); m != 1 {
panic(err)
}
fmt.Println(`Enter the integers`)
all := make([]int, n)
ReadN(all, 0, n)
fmt.Println(all)
}
func ReadN(all []int, i, n int) {
if n == 0 {
return
}
if m, err := fmt.Scan(&all[i]); m != 1 {
panic(err)
}
ReadN(all, i+1, n-1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment