push all exercices

This commit is contained in:
lbenedar
2026-02-21 14:09:13 +03:00
commit a94d994b8c
72 changed files with 787 additions and 0 deletions

BIN
ch5/2/ch5_2.exe Normal file

Binary file not shown.

44
ch5/2/ch5_2.go Normal file
View File

@@ -0,0 +1,44 @@
package main
import (
"errors"
"fmt"
"os"
)
func fileLen(filename string) (int, error) {
const blockSize = 128
file, err := os.Open(filename)
if err != nil {
fmt.Println("Could not open file!")
return 0, err
}
defer file.Close()
dataBlock := make([]byte, blockSize)
totalCount := 0
for {
count, err := file.Read(dataBlock)
if err != nil {
return 0, err
}
totalCount += count
if count < blockSize {
break
}
}
return totalCount, nil
}
func main() {
if len(os.Args) < 2 {
err := errors.New("Program doesn't have any arguments. Please pass argument")
fmt.Println(err)
return
}
fileSize, err := fileLen(os.Args[1])
if err != nil {
fmt.Println(err)
return
}
fmt.Println(fileSize)
}

3
ch5/2/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module ch5_2
go 1.25.0