list initializer
This commit is contained in:
@@ -16,10 +16,11 @@ LIBS =
|
|||||||
INCLUDES = -I$(D_HEADERS)
|
INCLUDES = -I$(D_HEADERS)
|
||||||
|
|
||||||
D_SRCS = .
|
D_SRCS = .
|
||||||
SRCS = main.cpp
|
SRCS = main.cpp \
|
||||||
|
Sed.cpp
|
||||||
|
|
||||||
D_HEADERS = .
|
D_HEADERS = .
|
||||||
HEADERS =
|
HEADERS = Sed.hpp
|
||||||
|
|
||||||
D_OBJS = builds
|
D_OBJS = builds
|
||||||
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
|
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
|
||||||
|
|||||||
32
d01/ex04/Sed.cpp
Normal file
32
d01/ex04/Sed.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "Sed.hpp"
|
||||||
|
|
||||||
|
Sed::Sed(char *file, char *find, char *replacement)
|
||||||
|
: _file( file )
|
||||||
|
// , _new_file( file.append(".replace") )
|
||||||
|
, _find( find )
|
||||||
|
, _replacement( replacement )
|
||||||
|
{
|
||||||
|
|
||||||
|
// this->_buf =
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
Sed::~Sed() {
|
||||||
|
|
||||||
|
// delete[] this->_buf;
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sed::replace() {
|
||||||
|
|
||||||
|
std::ifstream file(this->_file.c_str());
|
||||||
|
char c;
|
||||||
|
|
||||||
|
while (file.get(c))
|
||||||
|
{
|
||||||
|
std::cout << c;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
27
d01/ex04/Sed.hpp
Normal file
27
d01/ex04/Sed.hpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef SED_HPP
|
||||||
|
# define SED_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
class Sed {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Sed(char *file, char *find, char *replacement);
|
||||||
|
~Sed();
|
||||||
|
|
||||||
|
void replace( void );
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// std::string _buf;
|
||||||
|
std::string const _file;
|
||||||
|
std::string const _new_file;
|
||||||
|
std::string const _find;
|
||||||
|
std::string const _replacement;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,24 +1,28 @@
|
|||||||
|
#include "Sed.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
int main() {
|
int sed_error(std::string msg) {
|
||||||
|
|
||||||
std::ifstream file("test.txt");
|
std::cout << msg << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// read words separated by whitespaces or newlines
|
void cpp_sed(char **av) {
|
||||||
// std::string str;
|
|
||||||
// while (file >> str)
|
|
||||||
// std::cout << str << std::endl;
|
|
||||||
|
|
||||||
// skip whitespaces or newlines
|
Sed sed(av[1], av[2], av[3]);
|
||||||
// char c;
|
|
||||||
// while (file >> c)
|
sed.replace();
|
||||||
// std::cout << c << std::endl;
|
|
||||||
|
}
|
||||||
// seems good
|
|
||||||
char c;
|
int main(int ac, char **av) {
|
||||||
while (file.get(c))
|
|
||||||
std::cout << c;
|
if (ac != 4)
|
||||||
|
return sed_error("you must provide 3 parameters : <file> <string 1> <string 2>");
|
||||||
|
cpp_sed(av);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
d01/ex04/sed
BIN
d01/ex04/sed
Binary file not shown.
Reference in New Issue
Block a user