「🔨」 fix(Phonebook): Fixed when a contact field is empty
This commit is contained in:
@ -6,10 +6,11 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/31 13:51:00 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 "PhoneBook.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -22,29 +23,37 @@ std::string getInput(std::string info) {
|
|||||||
return (input);
|
return (input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void emptyContact(Contact *contact) {
|
||||||
|
contact->setName("");
|
||||||
|
contact->setLastName("");
|
||||||
|
contact->setNickname("");
|
||||||
|
contact->setPhoneNbr("");
|
||||||
|
contact->setSecret("");
|
||||||
|
}
|
||||||
|
|
||||||
void PhoneBook::_add(void) {
|
void PhoneBook::_add(void) {
|
||||||
|
|
||||||
std::string input;
|
std::string input;
|
||||||
|
|
||||||
input = getInput("name");
|
input = getInput("name");
|
||||||
if (input.empty())
|
if (input.empty())
|
||||||
return ;
|
return emptyContact(&this->_contact[this->_index]);
|
||||||
this->_contact[this->_index].setName(input);
|
this->_contact[this->_index].setName(input);
|
||||||
input = getInput("last name");
|
input = getInput("last name");
|
||||||
if (input.empty())
|
if (input.empty())
|
||||||
return ;
|
return emptyContact(&this->_contact[this->_index]);
|
||||||
this->_contact[this->_index].setLastName(input);
|
this->_contact[this->_index].setLastName(input);
|
||||||
input = getInput("nickname");
|
input = getInput("nickname");
|
||||||
if (input.empty())
|
if (input.empty())
|
||||||
return ;
|
return emptyContact(&this->_contact[this->_index]);
|
||||||
this->_contact[this->_index].setNickname(input);
|
this->_contact[this->_index].setNickname(input);
|
||||||
input = getInput("phone number");
|
input = getInput("phone number");
|
||||||
if (input.empty())
|
if (input.empty())
|
||||||
return ;
|
return emptyContact(&this->_contact[this->_index]);
|
||||||
this->_contact[this->_index].setPhoneNbr(input);
|
this->_contact[this->_index].setPhoneNbr(input);
|
||||||
input = getInput("darkest secret");
|
input = getInput("darkest secret");
|
||||||
if (input.empty())
|
if (input.empty())
|
||||||
return ;
|
return emptyContact(&this->_contact[this->_index]);
|
||||||
this->_contact[this->_index].setSecret(input);
|
this->_contact[this->_index].setSecret(input);
|
||||||
this->_index++;
|
this->_index++;
|
||||||
if (this->_index > 7)
|
if (this->_index > 7)
|
||||||
|
Reference in New Issue
Block a user