update: adding the add function
This commit is contained in:
parent
e1694a698d
commit
ce42218b88
5 changed files with 76 additions and 19 deletions
|
|
@ -6,11 +6,10 @@
|
|||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/09/20 19:46:50 by rparodi ### ########.fr #
|
||||
# Updated: 2024/10/14 19:07:56 by rparodi ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
||||
# Variables
|
||||
|
||||
# Name
|
||||
|
|
@ -21,10 +20,15 @@ CXX = c++
|
|||
RM = rm -rf
|
||||
|
||||
# Flags
|
||||
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -g3
|
||||
|
||||
# Mandatory flags for 42 cpp
|
||||
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
|
||||
# Sources
|
||||
SRC = ./main.cpp
|
||||
SRC = ./phonebook.cpp \
|
||||
./main.cpp
|
||||
|
||||
# Objects
|
||||
OBJDIRNAME = ./build
|
||||
|
|
|
|||
|
|
@ -6,15 +6,52 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/20 19:42:14 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/20 20:03:13 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/14 19:06:54 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./phonebook.h"
|
||||
#include "phonebook.hpp"
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <strings.h>
|
||||
|
||||
bool adding(int index);
|
||||
bool adding(int index, contact array_contact[8])
|
||||
{
|
||||
std::string input;
|
||||
|
||||
if (index > 8 || index < 0)
|
||||
return (true);
|
||||
|
||||
std::cout << "Thanks to give the number of the new contact" << std::endl;
|
||||
std::getline(std::cin, input);
|
||||
if (input.length() != 10)
|
||||
return (true);
|
||||
array_contact[index].number = input;
|
||||
|
||||
std::cout << "Thanks to give the nickname of the new contact" << std::endl;
|
||||
std::getline(std::cin, input);
|
||||
array_contact[index].nickname = input;
|
||||
|
||||
std::cout << "Thanks to give the first_name of the new contact" << std::endl;
|
||||
std::getline(std::cin, input);
|
||||
array_contact[index].first_name = input;
|
||||
|
||||
std::cout << "Thanks to give the last_name of the new contact" << std::endl;
|
||||
std::getline(std::cin, input);
|
||||
array_contact[index].last_name = input;
|
||||
|
||||
std::cout << "Thanks to give the dark secret of the new contact" << std::endl;
|
||||
std::getline(std::cin, input);
|
||||
array_contact[index].dark_secret = input;
|
||||
|
||||
array_contact[index].id = index;
|
||||
|
||||
if (DEBUG)
|
||||
array_contact[index].print();
|
||||
return (false);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
|
@ -22,11 +59,19 @@ int main(void)
|
|||
int i;
|
||||
std::string input;
|
||||
|
||||
std::getline(std::cout, input, ':');
|
||||
if (strcmp(input.data, "ADD:"))
|
||||
adding(i);
|
||||
if (strcmp(input[i].data, "SEARCH:"))
|
||||
array_contact.print();
|
||||
if (strcmp(input.data, "EXIT:"))
|
||||
i = 0;
|
||||
while (true)
|
||||
{
|
||||
std::cout << MENU_TEXT << std::endl;
|
||||
std::getline(std::cin, input);
|
||||
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)
|
||||
return (0);
|
||||
input.clear();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -6,17 +6,18 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/20 19:50:03 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/20 19:50:51 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/14 18:52:45 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "phonebook.h"
|
||||
#include "phonebook.hpp"
|
||||
|
||||
void contact::print(void) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* phonebook.h :+: :+: :+: */
|
||||
/* phonebook.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/20 18:59:14 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/20 20:03:43 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/14 19:05:17 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,12 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#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"
|
||||
|
||||
#ifndef DEBUG
|
||||
# define DEBUG 0
|
||||
#endif
|
||||
|
||||
class contact {
|
||||
public:
|
||||
int id;
|
||||
|
|
@ -23,6 +29,7 @@ class contact {
|
|||
std::string first_name;
|
||||
std::string last_name;
|
||||
std::string nickname;
|
||||
std::string dark_secret;
|
||||
|
||||
void print(void);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue