Files
42_INT_09_piscine_cpp/d06/ex00/srcs/checkChar.cpp
2022-03-07 22:30:41 +01:00

41 lines
849 B
C++

#include "convert.h"
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]))
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 << B_YELLOW << str << RESET " is a char"
<< " of value "
<< B_CYAN << c << RESET << "\n";
fromChar(c);
return true;
}