Created
June 8, 2011 13:29
-
-
Save wingyplus/1014412 to your computer and use it in GitHub Desktop.
line count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io/ioutil" | |
"fmt" | |
"os" | |
) | |
func main () { | |
if len (os.Args) > 1 { | |
// Open file return []byte | |
fileByte, _ := ioutil.ReadFile (os.Args[1]) | |
// Check len of []byte | |
lineCount := 0 | |
for i := 0; i < len (fileByte); i++ { | |
c := fileByte[i] | |
if c == 10 || i == len (fileByte) - 1 { | |
lineCount++ | |
} | |
} | |
fmt.Println (lineCount) | |
} else { | |
fmt.Println ("lc [file]") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment