fix: typos in input scanning
This commit is contained in:
@ -14,12 +14,12 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create a new scanner that scans from the standard-input
|
||||
in := bufio.NewScanner(os.Stdin)
|
||||
|
||||
// Simulate an error
|
||||
// os.Stdin.Close()
|
||||
|
||||
// Create a new scanner that scans from the standard-input
|
||||
in := bufio.NewScanner(os.Stdin)
|
||||
|
||||
// Stores the total number of lines in the input
|
||||
var lines int
|
||||
|
||||
@ -32,10 +32,9 @@ func main() {
|
||||
// fmt.Println("Scanned Bytes:", in.Bytes())
|
||||
in.Text()
|
||||
}
|
||||
fmt.Printf("There %d lines.\n", lines)
|
||||
fmt.Printf("There are %d line(s)\n", lines)
|
||||
|
||||
err := in.Err()
|
||||
if err != nil {
|
||||
if err := in.Err(); err != nil {
|
||||
fmt.Println("ERROR:", err)
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,16 @@ func main() {
|
||||
}
|
||||
query := args[0]
|
||||
|
||||
rx := regexp.MustCompile(`[^a-z]+`)
|
||||
|
||||
in := bufio.NewScanner(os.Stdin)
|
||||
in.Split(bufio.ScanWords)
|
||||
|
||||
rx := regexp.MustCompile(`[^a-z]+`)
|
||||
|
||||
words := make(map[string]bool)
|
||||
for in.Scan() {
|
||||
word := strings.ToLower(in.Text())
|
||||
word = rx.ReplaceAllString(word, "")
|
||||
|
||||
if len(word) > 2 {
|
||||
words[word] = true
|
||||
}
|
||||
@ -45,7 +46,7 @@ func main() {
|
||||
fmt.Printf("The input contains %q.\n", query)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Sorry. The input does contain %q.\n", query)
|
||||
fmt.Printf("Sorry. The input does not contain %q.\n", query)
|
||||
|
||||
// query := "sun"
|
||||
// fmt.Println("sun:", words["sun"], "tesla:", words["tesla"])
|
||||
@ -55,5 +56,5 @@ func main() {
|
||||
// fmt.Printf("The input contains %q.\n", query)
|
||||
// return
|
||||
// }
|
||||
// fmt.Printf("Sorry. The input does contain %q.\n", query)
|
||||
// fmt.Printf("Sorry. The input does not contain %q.\n", query)
|
||||
}
|
||||
|
Reference in New Issue
Block a user