d00 ex01 phonebook resolu pbms
This commit is contained in:
@@ -16,51 +16,55 @@ void PhoneBook::add_contact() {
|
||||
std::string str;
|
||||
int it;
|
||||
|
||||
this->_contact_count++;
|
||||
it = this->_contact_count;
|
||||
if (it > 8)
|
||||
it = 1;
|
||||
it--;
|
||||
it = this->_contact_count % 8;
|
||||
this->_contact[it].clear_contact();
|
||||
|
||||
std::cout << B_CYAN "enter a first name pliz :" << std::endl;
|
||||
while (_contact[it].get_first().length() == 0)
|
||||
while (this->_contact[it].get_first().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
if (!std::getline(std::cin, str))
|
||||
return;
|
||||
this->_contact[it].add_first(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a last name pliz :" << std::endl;
|
||||
while (_contact[it].get_last().length() == 0)
|
||||
while (this->_contact[it].get_last().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
if (!std::getline(std::cin, str))
|
||||
return;
|
||||
this->_contact[it].add_last(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a nickname pliz :" << std::endl;
|
||||
while (_contact[it].get_nick().length() == 0)
|
||||
while (this->_contact[it].get_nick().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
if (!std::getline(std::cin, str))
|
||||
return;
|
||||
this->_contact[it].add_nick(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a number pliz :" << std::endl;
|
||||
while (_contact[it].get_num().length() == 0)
|
||||
while (this->_contact[it].get_num().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
if (!std::getline(std::cin, str))
|
||||
return;
|
||||
this->_contact[it].add_num(str);
|
||||
}
|
||||
|
||||
std::cout << B_CYAN "enter a secret of this contact pliz :" << std::endl;
|
||||
while (_contact[it].get_secret().length() == 0)
|
||||
while (this->_contact[it].get_secret().length() == 0)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, str);
|
||||
if (!std::getline(std::cin, str))
|
||||
return;
|
||||
this->_contact[it].add_secret(str);
|
||||
}
|
||||
|
||||
this->_contact_count++;
|
||||
}
|
||||
|
||||
std::string truncate(std::string str, size_t len) {
|
||||
@@ -117,19 +121,22 @@ void PhoneBook::print_contact( int id ) {
|
||||
void PhoneBook::search_contact() {
|
||||
|
||||
std::string index;
|
||||
int id;
|
||||
long id;
|
||||
char *ret;
|
||||
|
||||
if (this->print_phonebook() == 0)
|
||||
return;
|
||||
id = -1;
|
||||
std::cout << std::endl << B_CYAN "choose an index :" << std::endl;
|
||||
while (id < 0 || id > this->_contact_count - 1 || id > 7)
|
||||
while (1)
|
||||
{
|
||||
std::cout << B_BLUE "-> " RESET;
|
||||
std::getline(std::cin, index);
|
||||
id = std::atoi(index.c_str());
|
||||
if (id < 0 || id > this->_contact_count - 1 || id > 7)
|
||||
if (!std::getline(std::cin, index))
|
||||
return;
|
||||
id = std::strtol(index.c_str(), &ret, 10);
|
||||
if (*ret || id < 0 || id > this->_contact_count - 1 || id > 7)
|
||||
std::cout << B_RED "sorry, not a valid index" RESET << std::endl;
|
||||
else
|
||||
break;
|
||||
}
|
||||
this->print_contact(id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user