plinius
asked on
most efficient method to do this
Hi,
I made a program to make all possible "words" (from a to zzzzz for example) which uses this function:
***
char increaseChar (char value)
{
if (value != ' z' ) return ( char (value + 1) );
else return 'a';
}
***
Now I want to adapt the program so that you can define your own alphabet (for example "azerty123&é" )
What is the best way to do this??
How should I adapt the increasechar function to do this??
Or is there a better way ??
(like using an "enum" , or something like this ? )
Could you also give a code sample please, since I am a beginner.
I made a program to make all possible "words" (from a to zzzzz for example) which uses this function:
***
char increaseChar (char value)
{
if (value != ' z' ) return ( char (value + 1) );
else return 'a';
}
***
Now I want to adapt the program so that you can define your own alphabet (for example "azerty123&é" )
What is the best way to do this??
How should I adapt the increasechar function to do this??
Or is there a better way ??
(like using an "enum" , or something like this ? )
Could you also give a code sample please, since I am a beginner.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks all for your answers.
rstaveley, this wasn't exactly what I ment, but thanks anyway.
I used anthony_w's example.
rstaveley, this wasn't exactly what I ment, but thanks anyway.
I used anthony_w's example.
The following maps characters 'A'-'Z' and 'a'-'z':
--------8<--------
#include <iostream>
#include <string>
#include <algorithm>
char togibber(char c)
{
static const char upper[] = "QWERTYUIOPASDFGHJKLZXCVBN
static const char lower[] = "qwertyuiopasdfghjklzxcvbn
if (c >= 'A' && c <= 'Z')
return upper[c-'A'];
if (c >= 'a' && c <= 'z')
return lower[c-'a'];
return c;
}
int main()
{
std::string str = "Hello, confused world";
transform(str.begin(),str.
std::cout << str << '\n';
}
--------8<--------