first commit, working version of define-cli
This commit is contained in:
commit
298a4aa69b
BIN
define-cli
Executable file
BIN
define-cli
Executable file
Binary file not shown.
72325
dictionary.txt
Normal file
72325
dictionary.txt
Normal file
File diff suppressed because it is too large
Load Diff
52
main.go
Normal file
52
main.go
Normal file
@ -0,0 +1,52 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user