update: adding colors and the debug mode

This commit is contained in:
Raphael 2024-10-15 00:15:21 +02:00
parent ce42218b88
commit 9d476992bc
5 changed files with 55 additions and 20 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
build/
*.d
*.o
phonebook
megaphone

View file

@ -6,7 +6,7 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2024/10/14 19:07:56 by rparodi ### ########.fr #
# Updated: 2024/10/14 23:43:03 by rparodi ### ########.fr #
# #
# **************************************************************************** #
@ -25,7 +25,7 @@ CXXFLAGS = -Werror -Wextra -Wall -std=c++98
# Flags to debug and have the dependences (can be removed for correction)
CXXFLAGS += -MMD -g3
# Flag to debug (TO REMOVE)
# CXXFLAGS += -D DEBUG=1
CXXFLAGS += -D DEBUG=1
# Sources
SRC = ./phonebook.cpp \
./main.cpp

View file

@ -6,17 +6,20 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/20 19:42:14 by rparodi #+# #+# */
/* Updated: 2024/10/14 19:06:54 by rparodi ### ########.fr */
/* Updated: 2024/10/15 00:14:12 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "phonebook.hpp"
#include <iostream>
#include <ostream>
#include <string>
#include <cstring>
#include <strings.h>
/**
* @brief Adding a new contact
*
* @param index index for the new contact
* @param array_contact the array asked by the subject
* @return true on error
*/
bool adding(int index, contact array_contact[8])
{
std::string input;
@ -47,9 +50,20 @@ bool adding(int index, contact array_contact[8])
array_contact[index].dark_secret = input;
array_contact[index].id = index;
time_t now = time(0);
array_contact[index].creation_time = localtime(&now);
if (DEBUG)
array_contact[index].print();
array_contact[index]._debug();
return (false);
}
bool searching(contact contact[8], int index)
{
if (index == 0)
return (true);
for (int i = 0; i < index; i++)
contact[i]._debug();
return (false);
}
@ -64,14 +78,18 @@ int main(void)
{
std::cout << MENU_TEXT << std::endl;
std::getline(std::cin, input);
if (strcmp(input.c_str(), "ADD:") == 0)
if (strcmp(input.c_str(), "ADD") == 0)
{
if (adding(i, array_contact))
std::cerr << "Error: during the adding process" << std::endl;
if (strcmp(input.c_str(), "SEARCH:") == 0)
/*if (searching(array_contact))*/;
if (strcmp(input.c_str(), "EXIT:") == 0)
std::cerr << RED << "\nError: during the adding process\n" << RESET << std::endl;
else
i++;
}
if (strcmp(input.c_str(), "SEARCH") == 0)
if (searching(array_contact, i))
std::cerr << RED << "\nError: during the searching process\n" << RESET << std::endl;
if (strcmp(input.c_str(), "EXIT") == 0)
return (0);
input.clear();
i++;
}
}

View file

@ -6,18 +6,22 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/20 19:50:03 by rparodi #+# #+# */
/* Updated: 2024/10/14 18:52:45 by rparodi ### ########.fr */
/* Updated: 2024/10/15 00:13:03 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "phonebook.hpp"
#include <iostream>
void contact::print(void) {
void contact::print(void) {
std::cout << GREY;
std::cout << "Creation Hour:" << creation_time << std::endl;
std::cout << "First Name:" << first_name << std::endl;
std::cout << "Last Name:" << last_name << std::endl;
std::cout << "Nickname:" << nickname << std::endl;
std::cout << "Number:" << number << std::endl;
std::cout << "Dark Secret:" << dark_secret << std::endl;
std::cout << "ID:" << id << std::endl;
std::cout << RESET;
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/20 18:59:14 by rparodi #+# #+# */
/* Updated: 2024/10/14 19:05:17 by rparodi ### ########.fr */
/* Updated: 2024/10/15 00:14:00 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,9 +14,17 @@
#define PHONEBOOK_H
#include <iostream>
#include <ostream>
#include <string>
#include <cstring>
#include <ctime>
#define MENU_TEXT "You're in the main menu:\nHere's the command:\n\t- ADD: To add a new contact\n\t- SEARCH: To search a contact\n\t- EXIT: to exit the program"
#define MENU_TEXT "You're in the main menu:\nHere's the command:\n\t- " << BLUE << "ADD: " << RESET << "To add a new contact\n\t- " BLUE << "SEARCH: " << RESET "To search a contact\n\t- " BLUE << "EXIT: " << RESET "to exit the program"
#define GREY "\033[0;90m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define BLUE "\033[34m"
#define RESET "\033[0m"
#ifndef DEBUG
# define DEBUG 0
@ -30,8 +38,8 @@ class contact {
std::string last_name;
std::string nickname;
std::string dark_secret;
void print(void);
struct tm *creation_time;
void _debug(void);
};
#endif