diff --git a/cpp00/ex01/Makefile b/cpp00/ex01/Makefile index 5902629..9c2da95 100644 --- a/cpp00/ex01/Makefile +++ b/cpp00/ex01/Makefile @@ -6,11 +6,10 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/09/20 19:46:50 by rparodi ### ########.fr # +# Updated: 2024/10/14 19:07:56 by rparodi ### ########.fr # # # # **************************************************************************** # - # Variables # Name @@ -21,10 +20,15 @@ CXX = c++ RM = rm -rf # Flags -CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -g3 - +# Mandatory flags for 42 cpp +CXXFLAGS = -Werror -Wextra -Wall -std=c++98 +# Flags to debug and have the dependences (can be removed for correction) +CXXFLAGS += -MMD -g3 +# Flag to debug (TO REMOVE) +# CXXFLAGS += -D DEBUG=1 # Sources -SRC = ./main.cpp +SRC = ./phonebook.cpp \ + ./main.cpp # Objects OBJDIRNAME = ./build diff --git a/cpp00/ex01/main.cpp b/cpp00/ex01/main.cpp index 5139ea9..d8afc9e 100644 --- a/cpp00/ex01/main.cpp +++ b/cpp00/ex01/main.cpp @@ -6,15 +6,52 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/20 19:42:14 by rparodi #+# #+# */ -/* Updated: 2024/09/20 20:03:13 by rparodi ### ########.fr */ +/* Updated: 2024/10/14 19:06:54 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ -#include "./phonebook.h" +#include "phonebook.hpp" +#include +#include #include #include +#include -bool adding(int index); +bool adding(int index, contact array_contact[8]) +{ + std::string input; + + if (index > 8 || index < 0) + return (true); + + std::cout << "Thanks to give the number of the new contact" << std::endl; + std::getline(std::cin, input); + if (input.length() != 10) + return (true); + array_contact[index].number = input; + + std::cout << "Thanks to give the nickname of the new contact" << std::endl; + std::getline(std::cin, input); + array_contact[index].nickname = input; + + std::cout << "Thanks to give the first_name of the new contact" << std::endl; + std::getline(std::cin, input); + array_contact[index].first_name = input; + + std::cout << "Thanks to give the last_name of the new contact" << std::endl; + std::getline(std::cin, input); + array_contact[index].last_name = input; + + std::cout << "Thanks to give the dark secret of the new contact" << std::endl; + std::getline(std::cin, input); + array_contact[index].dark_secret = input; + + array_contact[index].id = index; + + if (DEBUG) + array_contact[index].print(); + return (false); +} int main(void) { @@ -22,11 +59,19 @@ int main(void) int i; std::string input; - std::getline(std::cout, input, ':'); - if (strcmp(input.data, "ADD:")) - adding(i); - if (strcmp(input[i].data, "SEARCH:")) - array_contact.print(); - if (strcmp(input.data, "EXIT:")) - return (0); + i = 0; + while (true) + { + std::cout << MENU_TEXT << std::endl; + std::getline(std::cin, input); + if (strcmp(input.c_str(), "ADD:") == 0) + if (adding(i, array_contact)) + std::cerr << "Error: during the adding process" << std::endl; + if (strcmp(input.c_str(), "SEARCH:") == 0) + /*if (searching(array_contact))*/; + if (strcmp(input.c_str(), "EXIT:") == 0) + return (0); + input.clear(); + i++; + } } diff --git a/cpp00/ex01/phonebook b/cpp00/ex01/phonebook deleted file mode 100644 index 7068b99..0000000 Binary files a/cpp00/ex01/phonebook and /dev/null differ diff --git a/cpp00/ex01/phonebook.cpp b/cpp00/ex01/phonebook.cpp index f615e94..a52f150 100644 --- a/cpp00/ex01/phonebook.cpp +++ b/cpp00/ex01/phonebook.cpp @@ -6,17 +6,18 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/20 19:50:03 by rparodi #+# #+# */ -/* Updated: 2024/09/20 19:50:51 by rparodi ### ########.fr */ +/* Updated: 2024/10/14 18:52:45 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ -#include "phonebook.h" +#include "phonebook.hpp" void contact::print(void) { std::cout << "First Name:" << first_name << std::endl; std::cout << "Last Name:" << last_name << std::endl; std::cout << "Nickname:" << nickname << std::endl; std::cout << "Number:" << number << std::endl; + std::cout << "Dark Secret:" << dark_secret << std::endl; std::cout << "ID:" << id << std::endl; } diff --git a/cpp00/ex01/phonebook.h b/cpp00/ex01/phonebook.hpp similarity index 73% rename from cpp00/ex01/phonebook.h rename to cpp00/ex01/phonebook.hpp index 4162319..c008e67 100644 --- a/cpp00/ex01/phonebook.h +++ b/cpp00/ex01/phonebook.hpp @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* phonebook.h :+: :+: :+: */ +/* phonebook.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/20 18:59:14 by rparodi #+# #+# */ -/* Updated: 2024/09/20 20:03:43 by rparodi ### ########.fr */ +/* Updated: 2024/10/14 19:05:17 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,12 @@ #include #include +#define MENU_TEXT "You're in the main menu:\nHere's the command:\n\t- ADD: To add a new contact\n\t- SEARCH: To search a contact\n\t- EXIT: to exit the program" + +#ifndef DEBUG +# define DEBUG 0 +#endif + class contact { public: int id; @@ -23,6 +29,7 @@ class contact { std::string first_name; std::string last_name; std::string nickname; + std::string dark_secret; void print(void); };