September 2017
Intermediate to advanced
466 pages
9h 33m
English
The name of this implementation will be WCbuffered.go and will be presented in five parts.
The first part of the utility is the following:
package main
import (
"bufio"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
)
type File struct {
Filename string
Lines int
Words int
Characters int
Error error
}
The File structure will keep the counts for each input file. The second chunk of WCbuffered.go has the following Go code:
func monitor(values <-chan File, count int) { var totalWords int = 0 var totalLines int = 0 var totalChars int = 0 for i := 0; i < count; i++ { x := <-values totalWords = totalWords + x.Words totalLines = totalLines + x.Lines totalChars = totalChars + x.Characters if x.Error == nil { fmt.Printf("\t%d\t", ...Read now
Unlock full access