diff --git a/golangr/file-reader/main.go b/golangr/file-reader/main.go index 75215fe..0f9803e 100644 --- a/golangr/file-reader/main.go +++ b/golangr/file-reader/main.go @@ -17,22 +17,26 @@ func main() { } filePath := os.Args[1] + randWord := getWord(filePath) - file, err := os.Open(filePath) + fmt.Printf("The chosen name is %v\n", randWord) + +} + +func getWord(path string) (word string) { + + file, err := os.Open(path) if err != nil { - fmt.Print(err) + fmt.Println(err) } defer file.Close() scanner := bufio.NewScanner(file) + for scanner.Scan() { names = append(names, scanner.Text()) } - fmt.Println(names) - //fmt.Println(len(names)) - - randName := rand.Intn(len(names) - 0) - fmt.Printf("The chosen name is %v\n", names[randName]) - + randName := names[rand.Intn(len(names)-0)] + return randName }