Hello All, I am trying to convert a series of letters in char(not string) to numbers. I have setup the switch case but it doesnt seems to work. If someone can take a look and give me a hint I would really appreciate it.
Thank you.
this really should do it, you assign the character into an int variable and it will convert it.
using switch just like your code doesnt make any sense.
EDIT:
in your code, suit holds the characters.
in ascii, character 'p' is 112 in int
If you want p, t, c, and d to map to 0, 1, 2, and 3 then just use a c-string:
int charToInt(char suit)
{
static const char *map="ptcd";
const char *where = strchr(map, p);
return (where ? where-map : -1);
}
You could use a std::string also but this will save a few bytes because it won't copy the string to the heap.