update: finishing for good the last exercice
This commit is contained in:
parent
afd6bd90af
commit
4e8dc67e65
3 changed files with 13 additions and 7 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -11,3 +11,5 @@ BraiiiiiiinnnzzzZ
|
||||||
moar_brainz!
|
moar_brainz!
|
||||||
hi_this_is_brain
|
hi_this_is_brain
|
||||||
unnecessary_violence
|
unnecessary_violence
|
||||||
|
sed_is_for_loser
|
||||||
|
*.replace
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/11/05 15:26:18 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 ERR_PREFIX "Error:\n"
|
||||||
#define ARGS_MISSING "Please give 3 arguments: <filename> <to_replace> <by_word> !"
|
#define ARGS_MISSING "Please give 3 arguments: <filename> <to_replace> <by_word> !"
|
||||||
#define FILE_CANT_OPEN ": The file cannot be open !"
|
#define FILE_CANT_OPEN ": The file cannot be open !"
|
||||||
|
#define FILE_CANT_READ ": The file connot be read !"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,14 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/11/05 15:24:29 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 "sed.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
@ -23,13 +25,13 @@ int main(int argc, char *argv[])
|
||||||
std::ifstream input(argv[1]);
|
std::ifstream input(argv[1]);
|
||||||
if (!input)
|
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);
|
return (1);
|
||||||
}
|
}
|
||||||
Sed new_sed = Sed(argv, &input);
|
Sed new_sed = Sed(argv, &input);
|
||||||
std::ofstream output(new_sed.getFilename());
|
std::ofstream output(new_sed.getFilename());
|
||||||
if (!output.is_open()) {
|
if (!output.is_open()) {
|
||||||
std::cerr << "Error: Could not open the file for writing." << std::endl;
|
std::cerr << CLR_RED ERR_PREFIX << new_sed.getFilename() << FILE_CANT_OPEN CLR_RESET << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
while (new_sed.line(output))
|
while (new_sed.line(output))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue