fichiers organisés

This commit is contained in:
hugogogo
2022-03-07 15:16:05 +01:00
parent b8bf7e45dd
commit 142687283e
8 changed files with 159 additions and 78 deletions

View File

@@ -0,0 +1,30 @@
#include <iostream>
#include <string>
#include <cctype> // isdigit()
#include "color.h"
//Char toChar(str) {
//
//}
bool isChar(std::string str) {
if (str.length() != 1 || isdigit(str[0]))
return false;
return true;
}
bool checkChar(std::string str) {
// char c;
std::cout << "char\n";
if (str.length() != 1 || isdigit(str[0]))
return false;
// c = toChar(str);
// std::cout << "char"RESET" equal to : "B_CYAN << c << RESET << "\n";
// fromChar(c);
return true;
}

View File

@@ -0,0 +1,29 @@
#include <iostream>
#include <string>
#include <cctype> // isdigit()
#include "color.h"
//Char toChar(str) {
//
//}
bool isDouble(std::string str) {
if (str.length() == 3)
return true;
return false;
}
bool checkDouble(std::string str) {
// double d;
std::cout << "double\n";
if (!isDouble(str))
return false;
// d = toDouble(str);
// std::cout << "double"RESET" equal to : "B_CYAN << d << RESET << "\n";
// fromDouble(d);
return true;
}

View File

@@ -0,0 +1,30 @@
#include <iostream>
#include <string>
#include <cctype> // isdigit()
#include "color.h"
//Char toChar(str) {
//
//}
bool isFloat(std::string str) {
if (str.length() == 4)
return true;
return false;
}
bool checkFloat(std::string str) {
// float f;
std::cout << "in char\n";
if (!isFloat(str))
return false;
// f = toFloat(str);
// std::cout << "float"RESET" equal to : "B_CYAN << f << RESET << "\n";
// fromFloat(f);
return true;
}

View File

@@ -0,0 +1,30 @@
#include <iostream>
#include <string>
#include <cctype> // isdigit()
#include "color.h"
//Char toInt(str) {
//
//}
bool isInt(std::string str) {
if (str.length() == 2)
return true;
return false;
}
bool checkInt(std::string str) {
// int i;
std::cout << "int\n";
if (!isInt(str))
return false;
// i = toInt(str);
// std::cout << "int"RESET" equal to : "B_CYAN << i << RESET << "\n";
// fromInt(i);
return true;
}

31
d06/ex00/srcs/convert.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include <iostream>
#include <string>
#include "color.h"
bool checkChar(std::string str);
bool checkInt(std::string str);
bool checkFloat(std::string str);
bool checkDouble(std::string str);
bool isElse(std::string str) {
std::cout << str << B_RED " is not valid type for this exercise" RESET "\n";
return true;
}
bool (*checkFunc[])(std::string str) =
{
checkChar,
checkInt,
checkFloat,
checkDouble,
isElse
};
void convert(std::string str) {
int size = sizeof(checkFunc) / sizeof(checkFunc[0]);
for (int it = 0; it < size; it++)
if ((*checkFunc[it])(str))
break;
}