Make 'a' = 0, 'b' = 1, etc

So basically i'm supposed to change the values of the alphabet letters and single digit number to a=0,b=1,...,z=25,0=26,1=27,...,9=35.

Can you anyone suggest how to do this? I really don't understand pointers (if it can be done with them) and i just can't get any idea to make it work meaningfully.

I would have to print out these values, so if there is a way to have a value of '0' print "a" I would love you.
1
2
3
4
5
6
7
8
#include <cctype>

inline int getnumeric(char c)
{
    if (isalpha(c)) return tolower(c) - 'a';
    else if (isdigit(c)) return c - 22;
    return -1; // error
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
#include <cctype>

int main()
{
    const std::string look_up = "abcdefghijklmnopqrstuvwxyz0123456789" ;

    for( char c : "lower and UPPER CASE too #12689" )
    {
        if( std::isalnum(c) )
            std::cout << c << " => " << look_up.find( std::tolower(c) ) << '\n' ;
    }
}

http://coliru.stacked-crooked.com/a/f0da70ce947a794c
Topic archived. No new replies allowed.