Learning about formatIO

This commit is contained in:
Zack
2026-09-02 16:31:26 -04:00
parent d307eb2698
commit 1bae4e44b0
14 changed files with 98 additions and 11 deletions
+40
View File
@@ -0,0 +1,40 @@
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
var tlc, tcc, twc int
for _, fname := range os.Args[1:] {
var lc, cc, wc int
file, err := os.Open(fname)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
}
defer file.Close()
scan := bufio.NewScanner(file)
for scan.Scan() {
s := scan.Text()
wc += len(strings.Fields(s))
cc += len(s)
lc++
}
tlc += lc
tcc += cc
twc += wc
if err := scan.Err(); err != nil {
fmt.Printf("Invalid Input: %s", err)
}
fmt.Printf("%5d %5d %5d %s\n", lc, cc, wc, fname)
}
fmt.Printf("%5d %5d %5d %s\n", tlc, tcc, twc, "total")
}