Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab8 #508

Open
wants to merge 4 commits into
base: Pantiukov_Nikita
Choose a base branch
from
Open

Lab8 #508

wants to merge 4 commits into from

Conversation

Slicktty
Copy link

No description provided.

Comment on lines 23 to 39
func CreateAndWriteFile(filename string) {
file, _ := os.Create(filename)
defer file.Close()

fmt.Println("Введите текст для записи (завершите ввод пустой строкой):")
scanner := bufio.NewScanner(os.Stdin)

for scanner.Scan() {
line := scanner.Text()
if line == "" {
break
}
file.WriteString(line + "\n")
}

fmt.Println("Данные записаны в файл.")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделайте две разных функции. По правилам чистого кода переменная всегда должна выполнять только одну поставленную функцию, которая отражается в названии

@FeLL1kS
Copy link
Collaborator

FeLL1kS commented Dec 23, 2024

Конфликты

Comment on lines +34 to +46
func WriteToFile(file *os.File) {
defer file.Close()
fmt.Println("Введите текст для записи (завершите ввод пустой строкой):")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
if line == "" {
break
}
file.WriteString(line + "\n")
}
fmt.Println("Данные записаны в файл.")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ввод лучше сделать снаружи, а в функцию передавать данные, а не ждать их в логике внутри

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants