diff --git a/d06/ex00/Makefile b/d06/ex00/Makefile index cafdd50..7fd8a82 100644 --- a/d06/ex00/Makefile +++ b/d06/ex00/Makefile @@ -28,11 +28,16 @@ LIBS = INCLUDES = -I$(D_HEADERS) -D_SRCS = . -SRCS = main.cpp +D_SRCS = srcs +SRCS = main.cpp \ + convert.cpp \ + checkChar.cpp \ + checkInt.cpp \ + checkFloat.cpp \ + checkDouble.cpp D_HEADERS = . -HEADERS = +HEADERS = color.h D_OBJS = builds OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) diff --git a/d06/ex00/convert b/d06/ex00/convert index 2f596fe..e63a43b 100755 Binary files a/d06/ex00/convert and b/d06/ex00/convert differ diff --git a/d06/ex00/main.cpp b/d06/ex00/main.cpp index 64ce087..a6bbff4 100644 --- a/d06/ex00/main.cpp +++ b/d06/ex00/main.cpp @@ -1,8 +1,7 @@ #include #include -#include "color.h" -#include // isdigit() +void convert(std::string str); // 2^24 = 16777216; // 2^31 = 2147483648 @@ -14,79 +13,6 @@ #define MIN_INT_1 "-2147483649" #define MAX_FLOAT_INT_PRECISION "16777216" -//Char toChar(str) { -// -//} - -//bool isChar() {} - -bool checkChar(std::string str) { -// char c; -// -std::cout << "in 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; -} - -bool checkInt(std::string str) { -std::cout << "in int\n"; - if (str.length() == 1 || !isdigit(str[0])) - return false; - return true; -} - -bool checkFloat(std::string str) { -std::cout << "in int\n"; - if (str.length() == 1 || !isdigit(str[0])) - return false; - return true; -} - - -bool (*checkFunc[])(std::string str) = -{ - checkChar, - checkInt, - checkFloat -}; - -void convert(std::string str) { - - int size = sizeof(checkFunc) / sizeof(checkFunc[0]); - -// std::cout << str << " is a "B_YELLOW ; - - for (int it = 0; it < size; it++) - if ((*checkFunc[it])(str)) - break; - -// else if (isInt(str)) -// { -// i = toInt(str); -// std::cout << "int"RESET" equal to : "B_CYAN << i << RESET << "\n"; -// fromInt(i); -// } -// else if (isFloat(str)) -// { -// f = toFloat(str); -// std::cout << "float"RESET" equal to : "B_CYAN << f << RESET << "\n"; -// fromFloat(f); -// } -// else if (isDouble(str)) -// { -// d = toDouble(str); -// std::cout << "double"RESET" equal to : "B_CYAN << d << RESET << "\n"; -// fromDouble(d); -// } -// else -// std::cout << B_RED"not valid type"RESET"\n"; -} - int main(int ac, char **av) { if (ac > 1) diff --git a/d06/ex00/srcs/checkChar.cpp b/d06/ex00/srcs/checkChar.cpp new file mode 100644 index 0000000..62c6ba5 --- /dev/null +++ b/d06/ex00/srcs/checkChar.cpp @@ -0,0 +1,30 @@ +#include +#include +#include // 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; +} diff --git a/d06/ex00/srcs/checkDouble.cpp b/d06/ex00/srcs/checkDouble.cpp new file mode 100644 index 0000000..f22e14f --- /dev/null +++ b/d06/ex00/srcs/checkDouble.cpp @@ -0,0 +1,29 @@ +#include +#include +#include // 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; +} diff --git a/d06/ex00/srcs/checkFloat.cpp b/d06/ex00/srcs/checkFloat.cpp new file mode 100644 index 0000000..24da83b --- /dev/null +++ b/d06/ex00/srcs/checkFloat.cpp @@ -0,0 +1,30 @@ +#include +#include +#include // 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; +} diff --git a/d06/ex00/srcs/checkInt.cpp b/d06/ex00/srcs/checkInt.cpp new file mode 100644 index 0000000..91b4762 --- /dev/null +++ b/d06/ex00/srcs/checkInt.cpp @@ -0,0 +1,30 @@ +#include +#include +#include // 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; +} diff --git a/d06/ex00/srcs/convert.cpp b/d06/ex00/srcs/convert.cpp new file mode 100644 index 0000000..4102473 --- /dev/null +++ b/d06/ex00/srcs/convert.cpp @@ -0,0 +1,31 @@ +#include +#include +#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; +}