package main
import (
    "io"
	"os"
	"bufio"
	"fmt"
)
func main(){
	read_file,err := os.Open("D:/Golang/src/go_code/chapter36/main.txt")
    defer read_file.Close()
	if err != nil{
		fmt.Println("打开失败")
	}
	reader := bufio.NewReader(read_file)
	var chacount CharCount
	for{
		str,err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		strr := []rune(str)
	
		
        for _,v := range strr {
		
			switch{
			case v >= 'a' && v <= 'z':
				fallthrough
			case v >= 'A' && v <= 'Z':
				chacount.str++
	     	case v >= '1' && v <= '9':
			    chacount.num++
			case v == ' ' ||  v == '\t' || v=='\n':
			    chacount.space++
			default:
			    chacount.other++
		    }
		}
	}
	chacount.PrintInfo()
}
type CharCount struct{
	str int
	num int
	space int
	other int
}
func (charcount *CharCount) PrintInfo(){
	fmt.Printf("英文字符总共:%v 数字字符总共:%v 空格的个数为%v 其他字符为%v", charcount.str, charcount.num, charcount.space, charcount.other)
}