I have the following program that I want to show how many times a specific introduced line appears from stdin:
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
counts := make(map[string]int)
input := bufio.NewScanner(os.Stdin)
for input.Scan() {
counts[input.Text()]++
}
// NOTE: ignoring potential errors from input.Err()
for line, n := range counts {
if n > 1 {
fmt.Printf("%d\t%s
", n, line)
}
}
}
When I run the program it allows me to enter strings, but even when I press enter I don't get any feedback.
What am I missing here? I believe it gets stuked in the first for
.