1
0

Compare commits

...

14 Commits

31 changed files with 985 additions and 1 deletions

6
.gitignore vendored
View File

@ -3,3 +3,9 @@ compile_commands.json
.cache
.direnv
flake.lock
zombie
zombieHorde
thisisabrain
violence
sed
harl

57
ex00/Makefile Normal file
View File

@ -0,0 +1,57 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
# Updated: 2024/11/04 11:44:44 by adjoly ### ########.fr #
# #
# **************************************************************************** #
NAME = zombie
CC = c++
OBJSDIR = obj/
SRCS = main.cpp \
Zombie.cpp \
newZombie.cpp \
randomChump.cpp
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
PURPLE = \e[0;35m
NC = \033[0m
DELETE = \x1B[2K\r
all: $(NAME)
$(NAME): $(OBJS)
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
$(OBJSDIR)%.o: %.cpp
@mkdir -p $(@D)
@$(CC) $(FLAGS) -c $< -o $@
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
clean:
@rm -f $(OBJS)
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
fclean: clean
@rm -f $(NAME)
@rm -Rf $(OBJSDIR)
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
re: fclean all
.PHONY: clean fclean all re

27
ex00/Zombie.cpp Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 11:40:41 by adjoly #+# #+# */
/* Updated: 2024/11/04 14:56:23 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
#include <iostream>
Zombie::Zombie(std::string name) {
this->name = name;
std::cout << this->name << " born" << std::endl;
}
Zombie::~Zombie(void) {
std::cout << this->name << " destroyed" << std::endl;
}
void Zombie::announce(void) {
std::cout << this->name << ": BraiiiiiiinnnzzzZ..." << std::endl;
}

29
ex00/Zombie.hpp Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 10:52:33 by adjoly #+# #+# */
/* Updated: 2024/11/04 19:21:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <string>
class Zombie {
private:
std::string name;
public:
void announce(void);
Zombie(std::string name);
~Zombie(void);
};
Zombie *newZombie(std::string name);
void randomChump(std::string name);

24
ex00/main.cpp Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 11:41:07 by adjoly #+# #+# */
/* Updated: 2024/11/04 15:07:39 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
int main(void) {
Zombie *zombie;
zombie = newZombie("newZombieee");
zombie->announce();
delete zombie;
randomChump("Zombieee");
return (0);
}

22
ex00/newZombie.cpp Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* newZombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 14:42:36 by adjoly #+# #+# */
/* Updated: 2024/11/04 14:49:42 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include "Zombie.hpp"
Zombie *newZombie(std::string name) {
Zombie *zombie;
zombie = new Zombie(name);
return (zombie);
}

18
ex00/randomChump.cpp Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* randomChump.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 14:56:39 by adjoly #+# #+# */
/* Updated: 2024/11/04 14:57:22 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
void randomChump(std::string name) {
Zombie zombie(name);
zombie.announce();
}

56
ex01/Makefile Normal file
View File

@ -0,0 +1,56 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
# Updated: 2024/11/04 19:09:31 by adjoly ### ########.fr #
# #
# **************************************************************************** #
NAME = zombieHorde
CC = c++
OBJSDIR = obj/
SRCS = main.cpp \
Zombie.cpp \
zombieHorde.cpp
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP -g
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
PURPLE = \e[0;35m
NC = \033[0m
DELETE = \x1B[2K\r
all: $(NAME)
$(NAME): $(OBJS)
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
$(OBJSDIR)%.o: %.cpp
@mkdir -p $(@D)
@$(CC) $(FLAGS) -c $< -o $@
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
clean:
@rm -f $(OBJS)
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
fclean: clean
@rm -f $(NAME)
@rm -Rf $(OBJSDIR)
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
re: fclean all
.PHONY: clean fclean all re

30
ex01/Zombie.cpp Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 11:40:41 by adjoly #+# #+# */
/* Updated: 2024/11/04 18:47:10 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
#include <iostream>
Zombie::Zombie() {
std::cout << "Zombie born" << std::endl;
}
void Zombie::setName(std::string newName) {
this->name = newName;
}
Zombie::~Zombie(void) {
std::cout << this->name << " destroyed" << std::endl;
}
void Zombie::announce(void) {
std::cout << this->name << ": BraiiiiiiinnnzzzZ..." << std::endl;
}

31
ex01/Zombie.hpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 10:52:33 by adjoly #+# #+# */
/* Updated: 2024/11/04 19:22:07 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
# include <string>
# define uint8_t unsigned char
class Zombie {
private:
std::string name;
public:
void announce(void);
void setName(std::string newName);
Zombie(void);
~Zombie(void);
};
Zombie *zombieHorde(int n, std::string name);

27
ex01/main.cpp Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 11:41:07 by adjoly #+# #+# */
/* Updated: 2024/11/04 18:59:15 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
int main(void) {
Zombie *horde;
uint8_t i;
horde = zombieHorde(5, "Fabrice");
i = 0;
while (i < 5)
{
horde[i].announce();
i++;
}
delete[] horde;
}

26
ex01/zombieHorde.cpp Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zombieHorde.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 17:48:42 by adjoly #+# #+# */
/* Updated: 2024/11/04 18:43:09 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie *zombieHorde(int n, std::string name) {
Zombie *horde;
uint8_t i;
horde = new Zombie[n]();
i = 0;
while (i < n) {
horde[i].setName(name);
i++;
}
return (horde);
}

54
ex02/Makefile Normal file
View File

@ -0,0 +1,54 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
# Updated: 2024/11/04 19:17:46 by adjoly ### ########.fr #
# #
# **************************************************************************** #
NAME = thisisabrain
CC = c++
OBJSDIR = obj/
SRCS = main.cpp
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
PURPLE = \e[0;35m
NC = \033[0m
DELETE = \x1B[2K\r
all: $(NAME)
$(NAME): $(OBJS)
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
$(OBJSDIR)%.o: %.cpp
@mkdir -p $(@D)
@$(CC) $(FLAGS) -c $< -o $@
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
clean:
@rm -f $(OBJS)
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
fclean: clean
@rm -f $(NAME)
@rm -Rf $(OBJSDIR)
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
re: fclean all
.PHONY: clean fclean all re

30
ex02/main.cpp Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:01:36 by adjoly #+# #+# */
/* Updated: 2024/11/04 19:15:33 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <string>
int main(void) {
std::string str = "HI THIS IS BRAIN";
std::string *stringPTR = &str;
std::string &stringREF = str;
std::cout << "The address of the string : " << &str << std::endl;
std::cout << "The address of the string pointer : " << stringPTR << std::endl;
std::cout << "The address of the string reference : " << &stringREF << std::endl;
std::cout << std::endl;
std::cout << "The value of the string : " << str << std::endl;
std::cout << "The value pointed to by stringPTR : " << *stringPTR << std::endl;
std::cout << "The value pointed to by stringREF : " << stringREF << std::endl;
}

21
ex03/HumanA.cpp Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:41:23 by adjoly #+# #+# */
/* Updated: 2024/11/09 18:47:57 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include "HumanA.hpp"
#include "Weapon.hpp"
void HumanA::attack(void) {
std::cout << this->_name << " attacks with their " << this->_weapon.getType() << std::endl;
}
HumanA::HumanA(std::string name, Weapon &weapon) : _name(name), _weapon(weapon) { }

27
ex03/HumanA.hpp Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:36:00 by adjoly #+# #+# */
/* Updated: 2024/11/05 17:51:09 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include "Weapon.hpp"
#include <string>
class HumanA {
private:
std::string _name;
Weapon &_weapon;
public:
void attack(void);
HumanA(std::string name, Weapon &weapon);
};

24
ex03/HumanB.cpp Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:43:18 by adjoly #+# #+# */
/* Updated: 2024/11/09 18:48:06 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanB.hpp"
#include <iostream>
void HumanB::attack(void) {
std::cout << this->_name << " attacks with their " << this->_weapon->getType() << std::endl;
}
void HumanB::setWeapon(Weapon &newWeapon) {
this->_weapon = &newWeapon;
}
HumanB::HumanB(std::string name) : _name(name), _weapon(NULL) { }

28
ex03/HumanB.hpp Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:39:47 by adjoly #+# #+# */
/* Updated: 2024/11/05 17:53:56 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include "Weapon.hpp"
#include <string>
class HumanB {
private:
std::string _name;
Weapon *_weapon;
public:
void attack(void);
void setWeapon(Weapon &newWeapon);
HumanB(std::string name);
};

57
ex03/Makefile Normal file
View File

@ -0,0 +1,57 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
# Updated: 2024/11/05 17:11:17 by adjoly ### ########.fr #
# #
# **************************************************************************** #
NAME = violence
CC = c++
OBJSDIR = obj/
SRCS = main.cpp \
HumanA.cpp \
HumanB.cpp \
Weapon.cpp
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
PURPLE = \e[0;35m
NC = \033[0m
DELETE = \x1B[2K\r
all: $(NAME)
$(NAME): $(OBJS)
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
$(OBJSDIR)%.o: %.cpp
@mkdir -p $(@D)
@$(CC) $(FLAGS) -c $< -o $@
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
clean:
@rm -f $(OBJS)
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
fclean: clean
@rm -f $(NAME)
@rm -Rf $(OBJSDIR)
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
re: fclean all
.PHONY: clean fclean all re

23
ex03/Weapon.cpp Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:23:35 by adjoly #+# #+# */
/* Updated: 2024/11/09 18:46:35 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
void Weapon::setType(std::string newType) {
this->_type = newType;
}
const std::string &Weapon::getType(void) {
return (this->_type);
}
Weapon::Weapon(std::string type) : _type(type) { }

26
ex03/Weapon.hpp Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:21:24 by adjoly #+# #+# */
/* Updated: 2024/11/09 18:46:33 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <string>
class Weapon {
private:
std::string _type;
public:
const std::string &getType(void);
void setType(std::string newType);
Weapon(std::string type);
};

35
ex03/main.cpp Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 19:20:57 by adjoly #+# #+# */
/* Updated: 2024/11/05 17:43:17 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanA.hpp"
#include "HumanB.hpp"
#include <iostream>
int main()
{
{
Weapon club = Weapon("crude spiked club");
HumanA bob("Bob", club);
bob.attack();
club.setType("some other type of club");
bob.attack();
}
{
Weapon club = Weapon("crude spiked club");
HumanB jim("Jim");
jim.setWeapon(club);
jim.attack();
club.setType("some other type of club");
jim.attack();
}
return 0;
}

55
ex04/Makefile Normal file
View File

@ -0,0 +1,55 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
# Updated: 2024/11/07 18:45:24 by adjoly ### ########.fr #
# #
# **************************************************************************** #
NAME = sed
CC = c++
OBJSDIR = obj/
SRCS = main.cpp \
sed.cpp
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
PURPLE = \e[0;35m
NC = \033[0m
DELETE = \x1B[2K\r
all: $(NAME)
$(NAME): $(OBJS)
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
$(OBJSDIR)%.o: %.cpp
@mkdir -p $(@D)
@$(CC) $(FLAGS) -c $< -o $@
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
clean:
@rm -f $(OBJS)
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
fclean: clean
@rm -f $(NAME)
@rm -Rf $(OBJSDIR)
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
re: fclean all
.PHONY: clean fclean all re

27
ex04/main.cpp Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 18:11:15 by adjoly #+# #+# */
/* Updated: 2024/11/07 18:46:40 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "sed.h"
#include <iostream>
#include <string>
int main(int ac, char **av) {
if (!(ac > 2 && ac <= 4))
return (std::cerr << "Invalid number of args please only give ./sed <infile> <s1> <s2>" << std::endl, 1);
std::string infile = av[1];
std::string s1 = av[2];
std::string s2 = av[3];
Sed sed(infile, s1, s2);
return (0);
}

50
ex04/sed.cpp Normal file
View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sed.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 16:45:25 by adjoly #+# #+# */
/* Updated: 2024/11/09 18:49:49 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "sed.h"
Sed::Sed(std::string &inFile, std::string &s1, std::string &s2):
_outFileName(inFile + ".replace") {
std::ifstream infile(inFile.c_str());
size_t pos = 0;
std::stringstream buf;
if (!infile) {
std::cerr << "Could not open infile" << std::endl;
return ;
}
buf << infile.rdbuf();
_content = buf.str();
infile.close();
pos = _content.find(s1, pos);
while (pos < _content.length())
{
_content.erase(pos, s1.length());
_content.insert(pos, s2);
pos = _content.find(s1, pos + s2.length());
}
}
Sed::~Sed(void) {
std::ofstream outfile(this->_outFileName.c_str());
if (!outfile) {
std::cout << "Cannot write to outfile" << std::endl;
return ;
}
outfile << _content;
outfile.close();
}

27
ex04/sed.h Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sed.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 16:10:36 by adjoly #+# #+# */
/* Updated: 2024/11/07 18:36:27 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
# define fileExtension ".replace"
# include <string>
class Sed {
private:
std::string _outFileName;
std::string _content;
public:
Sed(std::string &inFile, std::string &s1, std::string &s2);
~Sed(void);
};

55
ex05/Makefile Normal file
View File

@ -0,0 +1,55 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
# Updated: 2024/11/09 16:15:35 by adjoly ### ########.fr #
# #
# **************************************************************************** #
NAME = harl
CC = c++
OBJSDIR = obj/
SRCS = main.cpp \
harl.cpp
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
PURPLE = \e[0;35m
NC = \033[0m
DELETE = \x1B[2K\r
all: $(NAME)
$(NAME): $(OBJS)
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
$(OBJSDIR)%.o: %.cpp
@mkdir -p $(@D)
@$(CC) $(FLAGS) -c $< -o $@
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
clean:
@rm -f $(OBJS)
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
fclean: clean
@rm -f $(NAME)
@rm -Rf $(OBJSDIR)
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
re: fclean all
.PHONY: clean fclean all re

42
ex05/harl.cpp Normal file
View File

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* harl.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/09 17:15:01 by adjoly #+# #+# */
/* Updated: 2024/11/09 19:16:07 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "harl.hpp"
#include <iostream>
void Harl::complain(std::string level) {
std::string complainLevel[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
void (Harl::*func[4])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
uint8_t i = 0;
while (i < 4 && level != complainLevel[i])
i++;
if (i < 4)
(this->*func[i])();
return ;
}
void Harl::debug(void) {
std::cout << "[DEBUG]: NixOS is the only true answer" << std::endl;
}
void Harl::info(void) {
std::cout << "[INFO]: NixOS is on 24.05" << std::endl;
}
void Harl::warning(void) {
std::cout << "[WARNING]: Please no Ubuntu here" << std::endl;
}
void Harl::error(void) {
std::cout << "[ERROR]: Arch issue switch to NixOS please for god sake" << std::endl;
}

28
ex05/harl.hpp Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/09 16:13:40 by adjoly #+# #+# */
/* Updated: 2024/11/09 17:35:57 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <string>
#define uint8_t unsigned char
class Harl {
private:
void debug(void);
void info(void);
void warning(void);
void error(void);
public:
void complain(std::string level);
};

22
ex05/main.cpp Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/09 16:12:06 by adjoly #+# #+# */
/* Updated: 2024/11/09 17:43:48 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "harl.hpp"
int main(void) {
Harl harl;
harl.complain("INFO");
harl.complain("DEBUG");
harl.complain("WARNING");
harl.complain("ERROR");
}

View File

@ -31,7 +31,7 @@
git
gdb
inputs.pogit.packages.${pkgs.system}.default
bear
python312Packages.compiledb
];
};
});