示例#1
0
文件: main.go 项目: mantishK/quiz
func buildTree(tc *tree.TreeCollection) {
	file, err := os.Open(fName)
	if err != nil {
		panic("File not found")
	}
	s := bufio.NewScanner(file)
	for s.Scan() {
		word := s.Text()
		tc.AddWord(word)
	}
	defer file.Close()
	if err := s.Err(); err != nil {
		panic("Error scanning file")
	}
}
示例#2
0
文件: main.go 项目: mantishK/quiz
func longCompWord(tc *tree.TreeCollection) string {
	maxLength := 0
	longWord := ""
	file, err := os.Open(fName)
	defer file.Close()
	if err != nil {
		panic("File not found")
	}
	s := bufio.NewScanner(file)
	for s.Scan() {
		word := s.Text()
		if tc.IsCompound(word) && maxLength < len(word) {
			longWord = word
			maxLength = len(word)
		}
	}
	if err := s.Err(); err != nil {
		panic("Error scanning file")
	}
	return longWord
}