aboutsummaryrefslogtreecommitdiff
path: root/cpp01/ex07
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-13 10:33:05 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-13 10:33:05 +0200
commit0f3240844dbd5a874e1565a988ef355ededab6a5 (patch)
treeefc1a1307863d173be17a12fbab6b84fe7d00960 /cpp01/ex07
parent629d52b1262879a346e9ca17567a8f483c60ba0a (diff)
downloadpiscine_cpp-0f3240844dbd5a874e1565a988ef355ededab6a5.tar.gz
piscine_cpp-0f3240844dbd5a874e1565a988ef355ededab6a5.tar.bz2
piscine_cpp-0f3240844dbd5a874e1565a988ef355ededab6a5.zip
Fixing cpp01
Diffstat (limited to 'cpp01/ex07')
-rw-r--r--cpp01/ex07/Makefile4
-rw-r--r--cpp01/ex07/main.cpp19
2 files changed, 15 insertions, 8 deletions
diff --git a/cpp01/ex07/Makefile b/cpp01/ex07/Makefile
index 7a649fc..1617d62 100644
--- a/cpp01/ex07/Makefile
+++ b/cpp01/ex07/Makefile
@@ -6,12 +6,12 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/02/02 17:05:31 by cacharle #+# #+# #
-# Updated: 2020/02/02 17:58:08 by cacharle ### ########.fr #
+# Updated: 2020/04/13 10:32:03 by charles ### ########.fr #
# #
# **************************************************************************** #
CXX = clang++
-CXXFLAGS= -Wall -Wextra #-Werror
+CXXFLAGS= -Wall -Wextra -Werror
SRC = $(shell find . -type f -name "*.cpp")
OBJ = $(SRC:.cpp=.o)
diff --git a/cpp01/ex07/main.cpp b/cpp01/ex07/main.cpp
index fbef95f..64e5ce8 100644
--- a/cpp01/ex07/main.cpp
+++ b/cpp01/ex07/main.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 17:08:28 by cacharle #+# #+# */
-/* Updated: 2020/02/02 18:00:25 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:31:55 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,12 +18,17 @@ int main(int argc, char **argv)
{
if (argc != 4)
{
- std::cerr << "Usage: " << argv[0] << " filename s1 s2";
+ std::cerr << "Usage: " << argv[0] << " filename s1 s2" << std::endl;
return 1;
}
std::string filename(argv[1]);
- std::string find_str(argv[2]);
- std::string replace_str(argv[3]);
+ std::string s1(argv[2]);
+ std::string s2(argv[3]);
+ if (s1 == "" || s2 == "")
+ {
+ std::cerr << "Error: s1 and s2 should not be empty" << std::endl;
+ return 1;
+ }
std::ifstream file(filename);
std::ofstream outfile(filename + ".replace");
@@ -39,18 +44,20 @@ int main(int argc, char **argv)
file.close();
return 1;
}
+
std::string line;
while (std::getline(file, line))
{
while (true)
{
- size_t i = line.find(find_str);
+ size_t i = line.find(s1);
if (i == std::string::npos)
break;
- line.replace(i, find_str.length(), replace_str);
+ line.replace(i, s1.length(), s2);
}
outfile << line << std::endl;
}
file.close();
outfile.close();
+ return 0;
}