Skip to content
Justice Tech School

Reading Input

fmt.Scan and bufio.Scanner read input. Here strings.NewReader replaces the keyboard.

Example
package main

import (
	"fmt"
	"strings"
)

func main() {
	r := strings.NewReader("42 Ada")
	var n int
	var name string
	fmt.Fscan(r, &n, &name)
	fmt.Println(n, name)
}

Result

42 Ada

Exercise

Read from a reader.

fmt.(r, &n)

Quiz Test

What does &n pass?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.