From 77c225d31e569d2f7074e39e0f14d433c64bc2f8 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 15 Oct 2024 00:51:11 +0200 Subject: [PATCH] feat: adding the check for the older one --- cpp00/ex01/main.cpp | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/cpp00/ex01/main.cpp b/cpp00/ex01/main.cpp index 155cb01..12b6f2f 100644 --- a/cpp00/ex01/main.cpp +++ b/cpp00/ex01/main.cpp @@ -6,11 +6,40 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/20 19:42:14 by rparodi #+# #+# */ -/* Updated: 2024/10/15 00:33:56 by rparodi ### ########.fr */ +/* Updated: 2024/10/15 00:50:51 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "phonebook.hpp" +#include +#include + +int get_older_contact(contact array_contact[8]) +{ + int ret = 0; + time_t remain = 0; + + for (int i = 0; i < 8; i++) + { + time_t tmp = mktime(array_contact[i].creation_time); + if (tmp == -1) + { + std::cerr << RED << "\nError: during the time process\n" << RESET << std::endl; + exit(1); + } + if (tmp > remain) + { + remain = mktime(array_contact[i].creation_time); + if (remain == -1) + { + std::cerr << RED << "\nError: during the time process\n" << RESET << std::endl; + exit(1); + } + ret = i; + } + } + return (ret); +} /** * @brief Adding a new contact @@ -57,7 +86,7 @@ bool adding(int index, contact array_contact[8]) return (false); } -bool searching(contact contact[8], int index) +bool searching(contact contact[8], int index) { if (index == 0) return (true); @@ -66,7 +95,7 @@ bool searching(contact contact[8], int index) return (false); } -int main(void) +int main(void) { contact array_contact[8]; int i;