Commit 579768e0 authored by Muhammad Falak R Wani's avatar Muhammad Falak R Wani Committed by Kevin Burke

fmt: add example for Fscanln

Updates golang/go#27376.

Change-Id: I9f33233f1aafa10941a63fcb4e49d351ea7ee246
Reviewed-on: https://go-review.googlesource.com/132675Reviewed-by: default avatarKevin Burke <kev@inburke.com>
Run-TryBot: Kevin Burke <kev@inburke.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 4d01f924
......@@ -6,6 +6,7 @@ package fmt_test
import (
"fmt"
"io"
"os"
"strings"
)
......@@ -77,3 +78,25 @@ func ExampleFprintln() {
// there are 99 gophers
// 21
}
func ExampleFscanln() {
s := `dmr 1771 1.61803398875
ken 271828 3.14159`
r := strings.NewReader(s)
var a string
var b int
var c float64
for {
n, err := fmt.Fscanln(r, &a, &b, &c)
if err == io.EOF {
break
}
if err != nil {
panic(err)
}
fmt.Printf("%d: %s, %d, %f\n", n, a, b, c)
}
// Output:
// 3: dmr, 1771, 1.618034
// 3: ken, 271828, 3.141590
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment