From c63eed9fc8c95ea5eff20dc34125185f08e9e5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=D0=BF=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D0=BA=D1=82=D0=B0?= Date: Thu, 26 Dec 2024 01:30:21 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'4.cpp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/4.cpp b/4.cpp index c87677d..61f87c9 100644 --- a/4.cpp +++ b/4.cpp @@ -91,19 +91,19 @@ int main() { } // 4.4 Открытие файла и загрузка его содержимого - FILE* file = fopen(fileName, "rb"); - if (file == nullptr) { - std::cerr << "Не удалось открыть файл!" << std::endl; + FILE* file = nullptr; + if (fopen_s(&file, fileName, "rb") != 0) { + perror("Ошибка при открытии файла"); return 1; } fseek(file, 0, SEEK_END); - long fileSize = ftell(file); + size_t fileSize = ftell(file); // Изменили на size_t для совместимости с большим размером fseek(file, 0, SEEK_SET); char* content = (char*)malloc(fileSize + 1); if (content == nullptr) { - std::cerr << "Ошибка выделения памяти!" << std::endl; + perror("Ошибка выделения памяти"); fclose(file); return 1; } @@ -132,4 +132,4 @@ int main() { printWords(text); return 0; -} +} \ No newline at end of file