From 604560d4cc53d0f41a96843accf221de37a55065 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Mon, 6 May 2019 16:31:25 +0300 Subject: [PATCH] fix: typos in input scanning --- 23-input-scanning/01-scanning/main.go | 11 +++++------ 23-input-scanning/02-map-as-sets/main.go | 9 +++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/23-input-scanning/01-scanning/main.go b/23-input-scanning/01-scanning/main.go index 0f49476..be0c3af 100644 --- a/23-input-scanning/01-scanning/main.go +++ b/23-input-scanning/01-scanning/main.go @@ -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) } } diff --git a/23-input-scanning/02-map-as-sets/main.go b/23-input-scanning/02-map-as-sets/main.go index 71426e4..378bcaa 100644 --- a/23-input-scanning/02-map-as-sets/main.go +++ b/23-input-scanning/02-map-as-sets/main.go @@ -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) }