update: log parser dir to input scanning

This commit is contained in:
Inanc Gumus
2019-05-05 18:23:52 +03:00
parent 1f4776b143
commit a40dc5b0a9
22 changed files with 56 additions and 10 deletions

View File

@ -0,0 +1,44 @@
package main
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
import (
"bufio"
"fmt"
"os"
)
func main() {
args := os.Args[1:]
if len(args) != 1 {
fmt.Println("Please type a search word.")
return
}
query := args[0]
in := bufio.NewScanner(os.Stdin)
in.Split(bufio.ScanWords)
// index the words
words := make(map[string]bool)
for in.Scan() {
words[in.Text()] = true
}
// unnecessary
// if _, ok := words[query]; ok {
// ...
// }
// answer the user query
if words[query] {
fmt.Printf("The input contains %q word.\n", query)
return
}
fmt.Printf("Sorry. The input does contain %q word.\n", query)
}