1
0

🔨」 fix(Phonebook): Fixed when a contact field is empty

This commit is contained in:
2024-11-04 13:06:13 +01:00
parent 381dc87b02
commit c7d6cd6115

View File

@ -6,10 +6,11 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <string>
#include <iostream>
@ -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)