Skip to content

Instantly share code, notes, and snippets.

@6LYTH3
Created June 9, 2011 15:11
Show Gist options
  • Save 6LYTH3/1016928 to your computer and use it in GitHub Desktop.
Save 6LYTH3/1016928 to your computer and use it in GitHub Desktop.
line count
package main
import (
"io/ioutil"
"bytes"
"os"
"fmt"
)
func main() {
var buff *bytes.Buffer
lCout := 0;
f, err := ioutil.ReadFile(os.Args[1])
buff = bytes.NewBuffer(f)
if f == nil {
fmt.Printf("can't open file\n err= %s\n", err.String())
os.Exit(1)
}else {
buffLen := buff.Len()
for i:=1;i<=buffLen;i++ {
RByte,_ := buff.ReadByte()
if RByte == 10 {
lCout++
}
}
fmt.Println(lCout)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment