I'm trying to run gopl.io/ch1/dup3 program from Donovan book on windows 7 using go version 1.7.3.
When I run the below program test.go, I get an empty line at the end. Is that for EOF? How do I distinguish it from an actual empty line?
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
func main() {
Counts := make(map[string]int)
for _, filename := range os.Args[1:] {
data, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %v
", os.Args[0], err)
continue
}
for _, line := range strings.Split(string(data), "
") {
counts[line]++
}
}
for line, n := range counts {
if n > 1 {
fmt.Printf("%d\t%s
", n, line)
}
}
}
with test.dat file:
Line number one
Line number two
Command:
> test.exe test.dat test.dat
Output is
2 Line number one
2 Line number two
2 <-- Here is the empty line.