Hello,
why the method Read of rot13Reader run twice?
This is the code:

package main

import (
        "fmt"
        "io"
        "os"
        "strings"
)

type rot13Reader struct {
        r io.Reader
}

var k int

func (rot *rot13Reader) Read(p []byte) (n int, err error) {
        k++
        n, err = rot.r.Read(p)
        for i := 0; i < len(p); i++ {
                if (p[i] >= 'A' && p[i] < 'N') || (p[i] >= 'a' && p[i] < 'n') {
                        p[i] += 13
                } else if (p[i] > 'M' && p[i] <= 'Z') || (p[i] > 'm' && p[i] <= 
'z') {
                        p[i] -= 13
                }
        }
        return
}

func main() {
        s := strings.NewReader("Lbh penpxrq gur pbqr!")
        r := rot13Reader{s}
        io.Copy(os.Stdout, &r)
        fmt.Println("\n", k)
}


Why after the execution the k value is 2?

T.i.a
Franco

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to