Figured out how to add file lines to array

This commit is contained in:
raul 2024-02-06 17:12:29 +01:00
parent 93bd23b848
commit 1bf9e3e27c
1 changed files with 9 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"os" "os"
) )
@ -16,18 +17,17 @@ func main() {
filePath := os.Args[1] filePath := os.Args[1]
names, err := fileReader(filePath) file, err := os.Open(filePath)
if err != nil { if err != nil {
fmt.Print(err) fmt.Print(err)
} }
fmt.Println(names) defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
names = append(names, scanner.Text())
} }
func fileReader(path string) (str string, err error) { fmt.Println(names)
b, err := os.ReadFile(path)
if err != nil {
fmt.Print(err)
}
stre := string(b)
return stre, err
} }