d06 ex00 all checks are ok

This commit is contained in:
hugogogo
2022-03-07 22:30:41 +01:00
parent 142687283e
commit 4ee3ae3e7d
10 changed files with 234 additions and 73 deletions

View File

@@ -1,11 +1,21 @@
#include <iostream>
#include <string>
#include <cctype> // isdigit()
#include "color.h"
#include "convert.h"
//Char toChar(str) {
//
//}
void fromChar(char c) {
int i;
float f;
double d;
i = static_cast<int>(c);
std::cout << std::setw(7) << std::left << "int" << B_CYAN << i << RESET "\n";
f = static_cast<float>(c);
std::cout << std::setw(7) << std::left << "float" << B_CYAN << f << RESET "\n";
d = static_cast<double>(c);
std::cout << std::setw(7) << std::left << "double" << B_CYAN << d << RESET "\n";
}
char toChar(std::string str) {
return str[0];
}
bool isChar(std::string str) {
if (str.length() != 1 || isdigit(str[0]))
@@ -14,17 +24,17 @@ bool isChar(std::string str) {
}
bool checkChar(std::string str) {
// char c;
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);
c = toChar(str);
std::cout << B_YELLOW << str << RESET " is a char"
<< " of value "
<< B_CYAN << c << RESET << "\n";
fromChar(c);
return true;
}