1
0
mirror of https://github.com/MADTeacher/go_basics.git synced 2025-11-29 05:36:55 +02:00
Files
go_basics/part_5/5.1/18.go
2025-06-14 12:40:10 +03:00

47 lines
694 B
Go

package main
import (
"fmt"
"log"
"os"
)
type Car struct {
model string
age uint8
weight float64
number string
}
func createCars() []Car {
return []Car{
{
model: "Oka",
weight: 13.22,
number: "ak1245j76",
age: 13,
},
{
model: "Lada7",
weight: 23.14,
number: "ak2147j175",
age: 1,
},
}
}
func main() {
myFile, err := os.Create("car_fprintf.txt")
if err != nil {
log.Fatal(err)
}
defer myFile.Close()
myCar := createCars()
for _, it := range myCar {
n, _ := fmt.Fprintf(myFile, "Model: %s ||Number: %s ||Age: %d ||Weight: %f\n",
it.model, it.number, it.age, it.weight)
fmt.Println("Записано: ", n, "байт")
}
}