Created
October 10, 2024 17:01
-
-
Save Darklega228/8a94d9476a45bdff531c53f3eb77a87c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
#pragma warning(disable:4996) | |
int main() | |
{ | |
setlocale(0, ""); | |
char word[100]; | |
char theme[100]; | |
while (true) | |
{ | |
cout << "Введите существительное (или 'exit' для завершения): "; | |
cin.getline(word, 100); | |
if (strcmp(word, "exit") == 0) | |
{ | |
break; | |
} | |
cout << "Введите тему (например, 'цветы', 'животные'): "; | |
cin.getline(theme, 100); | |
char path[150] = "C:/1/"; | |
strcat(path, theme); | |
strcat(path, ".txt"); | |
FILE* file = nullptr; | |
int error_code = fopen_s(&file, path, "a"); | |
if (file != nullptr) | |
{ | |
fputs(word, file); | |
fputs("\n", file); | |
fclose(file); | |
cout << "Слово \"" << word << "\" добавлено в файл \"" << path << "\".\n"; | |
} | |
else { | |
cout << "Ошибка открытия файла: " << path << "\n"; | |
} | |
} | |
cout << "Программа завершена.\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment