diff --git a/headFirst/args/main.go b/headFirst/args/main.go index 1726a55..369d77b 100644 --- a/headFirst/args/main.go +++ b/headFirst/args/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "main/sub" - "os" ) func jp (mylist ...int) { @@ -13,10 +12,10 @@ func jp (mylist ...int) { } func main() { - args := os.Args[1] - res := sub.Kek(args) - fmt.Println(res) - - jp(1,2,3,4) + // args := os.Args[1] + // res := sub.Kek(args) + // fmt.Println(res) + res := sub.Kek("data.txt") + jp(res...) } diff --git a/headFirst/maps/data.txt b/headFirst/maps/data.txt new file mode 100644 index 0000000..e4ea4b2 --- /dev/null +++ b/headFirst/maps/data.txt @@ -0,0 +1,9 @@ +Alexander +Alexey +Andrew +Vitaly +Alexander +Vitaly +Sergey +Sergey +Alexander diff --git a/headFirst/maps/go.mod b/headFirst/maps/go.mod new file mode 100644 index 0000000..1da823a --- /dev/null +++ b/headFirst/maps/go.mod @@ -0,0 +1,3 @@ +module main + +go 1.24.5 diff --git a/headFirst/maps/main.go b/headFirst/maps/main.go new file mode 100644 index 0000000..3b130f6 --- /dev/null +++ b/headFirst/maps/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "main/sub" +) + +func main() { + counter := make(map[string]int) + + ret := sub.Kek("data.txt") + for _,name := range ret { + counter[name]++ + } + for key,val := range counter { + fmt.Println(key,val) + } +} diff --git a/headFirst/maps/sub/sub.go b/headFirst/maps/sub/sub.go new file mode 100644 index 0000000..bcac798 --- /dev/null +++ b/headFirst/maps/sub/sub.go @@ -0,0 +1,21 @@ +package sub + +import ( + "bufio" + "log" + "os" +) + +func Kek(fileName string) []string { + var seg []string + file, err := os.Open(fileName) + if err != nil { + log.Fatal("Cannot open file") + } + scanner := bufio.NewScanner(file) + for scanner.Scan() { + seg = append(seg, scanner.Text()) + } + file.Close() + return seg +}