]> Cypherpunks.ru repositories - gostls13.git/commitdiff
fmt: add example for Fscanf
authorVenil Noronha <veniln@vmware.com>
Fri, 31 Aug 2018 17:11:22 +0000 (10:11 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Fri, 31 Aug 2018 18:27:09 +0000 (18:27 +0000)
Change-Id: Ia3dcb3a82e452fdcf0d087e8cd01ac01ca831c84
Reviewed-on: https://go-review.googlesource.com/132597
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Kevin Burke <kev@inburke.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>

src/fmt/example_test.go

index 1d2cc0d7574c97d3cd812c80558840989e4ed4a8..9b72d7a38376cf16eaa1a2261ee3d2fd24f6719b 100644 (file)
@@ -7,6 +7,7 @@ package fmt_test
 import (
        "fmt"
        "os"
+       "strings"
 )
 
 // The Errorf function lets us use formatting features
@@ -18,6 +19,24 @@ func ExampleErrorf() {
        // Output: user "bueller" (id 17) not found
 }
 
+func ExampleFscanf() {
+       var (
+               i int
+               b bool
+               s string
+       )
+       r := strings.NewReader("5 true gophers")
+       n, err := fmt.Fscanf(r, "%d %t %s", &i, &b, &s)
+       if err != nil {
+               panic(err)
+       }
+       fmt.Println(i, b, s)
+       fmt.Println(n)
+       // Output:
+       // 5 true gophers
+       // 3
+}
+
 func ExampleSprintf() {
        i := 30
        s := "Aug"