Skip to content

Instantly share code, notes, and snippets.

@erikh
Last active December 17, 2015 00:49
Show Gist options
  • Save erikh/5524381 to your computer and use it in GitHub Desktop.
Save erikh/5524381 to your computer and use it in GitHub Desktop.
full wc in go
package main
import "strings"
import "io"
import "bufio"
import "fmt"
import "os"
func main() {
reader := bufio.NewReader(os.Stdin)
var line string
var e error
var lines, words, chars int
for e != io.EOF {
line, e = reader.ReadString('\n')
this_char := len(line)
chars += this_char
if this_char > 1 {
lines++
words += len(strings.Fields(line))
}
}
fmt.Printf("%d lines, %d words, %d chars\n", lines, words, chars)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment