hereusement que ca marche parce que la gt proche de me tuer

This commit is contained in:
Camille Chauvet 2023-06-15 14:57:58 +00:00
parent 2e0f67ca59
commit 2a1dc87ca0
3 changed files with 27 additions and 6 deletions

View File

@ -37,7 +37,6 @@ Contact& Contact::operator=(Contact& src)
Contact::~Contact()
{
std::cout << "je suis finit: " << this << std::endl;
}
std::string Contact::to_string_partial() const

View File

@ -49,7 +49,8 @@ void PhoneBook::display_contacts()
Contact* PhoneBook::search(int index)
{
if ((size_t) index > this->len || index < 0)
std::cout << this->len << " " << index << std::endl;
if ((size_t) index >= this->len || index < 0)
return (NULL);
return (&this->contacts[index]);
}

View File

@ -38,19 +38,41 @@ int read_contact(Contact& contact)
return (0);
}
int isdigit(std::string& str)
{
for (size_t i = 0; i < str.size(); i++)
{
if (!std::isdigit(str[i]))
return(0);
std::cout << i << std::endl;
}
return (1);
}
Contact* search(PhoneBook &phone_book)
{
int index;
long index;
char *error;
std::string index_str;
Contact* contact;
contact = NULL;
while (contact == NULL)
{
index_str = "";
if (get_input(index_str, "index: "))
return (NULL);
index = std::atoi(index_str.c_str());
index = std::strtol(index_str.c_str(), &error, 10);
if (errno == ERANGE || error[0] != '\0')
{
std::cerr << "Invalid input" << std::endl;
errno = 0;
}
else {
contact = phone_book.search(index);
if (contact == NULL)
std::cerr << "Contact not found" << std::endl;
}
}
return (contact);
}
@ -71,7 +93,6 @@ int main()
{
if (read_contact(contact))
return (0);
std::cout << std::endl << "dasd" << std::endl;
phone_book.add_contact(contact);
}
else if (command == "SEARCH")