From 4e8dc67e653f6a636bcb89d070b8b8c55fd745cc Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 6 Nov 2024 16:41:58 +0100 Subject: [PATCH] update: finishing for good the last exercice --- .gitignore | 2 ++ cpp01/ex04/err_msg.hpp | 4 +++- cpp01/ex04/main.cpp | 14 ++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 27392e7..5144a17 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ BraiiiiiiinnnzzzZ moar_brainz! hi_this_is_brain unnecessary_violence +sed_is_for_loser +*.replace diff --git a/cpp01/ex04/err_msg.hpp b/cpp01/ex04/err_msg.hpp index 678bea4..7f229ce 100644 --- a/cpp01/ex04/err_msg.hpp +++ b/cpp01/ex04/err_msg.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/05 15:26:18 by rparodi #+# #+# */ -/* Updated: 2024/11/05 15:53:05 by rparodi ### ########.fr */ +/* Updated: 2024/11/06 16:35:49 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,4 +18,6 @@ #define ERR_PREFIX "Error:\n" #define ARGS_MISSING "Please give 3 arguments: !" #define FILE_CANT_OPEN ": The file cannot be open !" +#define FILE_CANT_READ ": The file connot be read !" + #endif diff --git a/cpp01/ex04/main.cpp b/cpp01/ex04/main.cpp index 2493842..27a0375 100644 --- a/cpp01/ex04/main.cpp +++ b/cpp01/ex04/main.cpp @@ -6,12 +6,14 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/05 15:24:29 by rparodi #+# #+# */ -/* Updated: 2024/11/06 16:09:06 by rparodi ### ########.fr */ +/* Updated: 2024/11/06 16:36:48 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ +#include "err_msg.hpp" #include "sed.hpp" #include +#include int main(int argc, char *argv[]) { @@ -23,15 +25,15 @@ int main(int argc, char *argv[]) std::ifstream input(argv[1]); if (!input) { - std::cout << CLR_RED ERR_PREFIX << argv[1] << FILE_CANT_OPEN << CLR_RESET << std::endl; + std::cerr << CLR_RED ERR_PREFIX << argv[1] << FILE_CANT_OPEN CLR_RESET << std::endl; return (1); } Sed new_sed = Sed(argv, &input); std::ofstream output(new_sed.getFilename()); - if (!output.is_open()) { - std::cerr << "Error: Could not open the file for writing." << std::endl; - return 1; - } + if (!output.is_open()) { + std::cerr << CLR_RED ERR_PREFIX << new_sed.getFilename() << FILE_CANT_OPEN CLR_RESET << std::endl; + return 1; + } while (new_sed.line(output)) { }