package main import ( "fmt" "os" "strings" "bufio" ) func main() { var userword string if len(os.Args) < 1 { reader := bufio.NewReader(os.Stdin) fmt.Println("Please enter the word you wish to define:\n") userword, _ = reader.ReadString('\n') } else { userword = os.Args[1] } file, err := os.Open("dictionary.txt") if err != nil { fmt.Println("Error! Dictionary file not opening!") } defer file.Close() scanner := bufio.NewScanner(file) itis := false for scanner.Scan() { //fmt.Println(scanner.Text()) definition := strings.Split(scanner.Text(), " ") ifso, _ := CompareStrings(definition[0], userword) if ifso { fmt.Println(scanner.Text()) itis = true } } if !(itis) { fmt.Println("No definition found") } if err := scanner.Err(); err != nil { fmt.Println(err) } } func CompareStrings(stringA, stringB string) (bool, error) { if strings.EqualFold(stringA, stringB) { return true, nil } else { return false, nil } }