From 9dd7a48967f99793b818f7362ac8e95717186774 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Tue, 10 Nov 2020 09:26:04 +0100 Subject: Added more tests for cpp01/07 --- cpp01/ex07/main.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'cpp01/ex07/main.cpp') diff --git a/cpp01/ex07/main.cpp b/cpp01/ex07/main.cpp index d98168a..3965d3d 100644 --- a/cpp01/ex07/main.cpp +++ b/cpp01/ex07/main.cpp @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 17:08:28 by cacharle #+# #+# */ -/* Updated: 2020/11/09 11:22:46 by cacharle ### ########.fr */ +/* Updated: 2020/11/10 09:25:28 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,22 +25,26 @@ int main(int argc, char **argv) std::string filename(argv[1]); std::string s1(argv[2]); std::string s2(argv[3]); - if (filename.empty() || s1.empty() || s2.empty()) + if (s1.empty() || s2.empty()) { - std::cerr << "Error: filename, s1 and s2 should not be empty" << std::endl; + std::cerr << "Error: s1 and s2 should not be empty" << std::endl; return 1; } std::ifstream file(filename); - std::ofstream outfile(filename + ".replace"); + std::ofstream outfile(filename + ".replace", std::ofstream::trunc); if (!file.is_open()) { - std::cerr << "Could not open " << filename; + std::cerr << "Could not open " << filename + << ": " << std::strerror(errno) << std::endl; + outfile.close(); return 1; } if (!outfile.is_open()) { - std::cerr << "Could not create " << filename << ".replace"; + std::cerr << "Could not create " << filename << ".replace" + << ": " << std::strerror(errno) << std::endl; + file.close(); return 1; } -- cgit