From c7d6cd61159c45d64b773aba2cb569d4dd74bb99 Mon Sep 17 00:00:00 2001 From: Adam JOLY Date: Mon, 4 Nov 2024 13:06:13 +0100 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix(Phonebook)?= =?UTF-8?q?:=20Fixed=20when=20a=20contact=20field=20is=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ex01/src/commands/add.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ex01/src/commands/add.cpp b/ex01/src/commands/add.cpp index afd88b1..01a4097 100644 --- a/ex01/src/commands/add.cpp +++ b/ex01/src/commands/add.cpp @@ -6,10 +6,11 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 13:51:00 by adjoly #+# #+# */ -/* Updated: 2024/11/04 10:43:18 by adjoly ### ########.fr */ +/* Updated: 2024/11/04 13:05:42 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ +#include "Contact.hpp" #include "PhoneBook.hpp" #include #include @@ -22,29 +23,37 @@ std::string getInput(std::string info) { return (input); } +void emptyContact(Contact *contact) { + contact->setName(""); + contact->setLastName(""); + contact->setNickname(""); + contact->setPhoneNbr(""); + contact->setSecret(""); +} + void PhoneBook::_add(void) { std::string input; input = getInput("name"); if (input.empty()) - return ; + return emptyContact(&this->_contact[this->_index]); this->_contact[this->_index].setName(input); input = getInput("last name"); if (input.empty()) - return ; + return emptyContact(&this->_contact[this->_index]); this->_contact[this->_index].setLastName(input); input = getInput("nickname"); if (input.empty()) - return ; + return emptyContact(&this->_contact[this->_index]); this->_contact[this->_index].setNickname(input); input = getInput("phone number"); if (input.empty()) - return ; + return emptyContact(&this->_contact[this->_index]); this->_contact[this->_index].setPhoneNbr(input); input = getInput("darkest secret"); if (input.empty()) - return ; + return emptyContact(&this->_contact[this->_index]); this->_contact[this->_index].setSecret(input); this->_index++; if (this->_index > 7)