-
Notifications
You must be signed in to change notification settings - Fork 112
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
base: Pantiukov_Nikita
Are you sure you want to change the base?
Lab8 #508
Conversation
golang/labs/lab8/lab8.go
Outdated
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("Данные записаны в файл.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сделайте две разных функции. По правилам чистого кода переменная всегда должна выполнять только одну поставленную функцию, которая отражается в названии
Конфликты |
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("Данные записаны в файл.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ввод лучше сделать снаружи, а в функцию передавать данные, а не ждать их в логике внутри
No description provided.