most efficient method to do this

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could do a look-up for all characters. Simply index the array using the character value.

The following maps characters 'A'-'Z' and 'a'-'z':
#include <iostream>
#include <string>
#include <algorithm>

char togibber(char c)
      static const char upper[] = "QWERTYUIOPASDFGHJKLZXCVBNM";
      static const char lower[] = "qwertyuiopasdfghjklzxcvbnm";

      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";
      std::cout << str << '\n';
Put the alphabet in an array and instead of using letters themselves, use numbers that index the array.  Then instead of calling an increaseChar function, you can just add 1 to the number.  Use the numbers as array subscripts to get the letters for output.

You could use a string object instead of an array if you want to be more C++y.

Sketchy example:

const char* alphabet = "blah";
int alphabetLength = strlen(alphabet);

// To generate all the two-letter words from this alphabet:

char word[3];
word[2] = '\0';
for (int sub1 = 0; sub1 < alphabetLength; ++sub1)
    for (int sub2 = 0; sub2 < alphabetLength; ++sub2)
        word[0] = alphabet[sub1];
        word[1] = alphabet[sub2];
        //  Save or output word somehow here.

(Clearly I had an interpretation of the question completely different from that of my esteemed colleague rstaveley.)

If you have your own alphabet, then you can rewrite increaseChar as below to return the next char, given a character from the alphabet, or the same character if given a character not there. You just then need to make your main loop deal with the custom alphabet.

char const alphabet[]="azerty123&é";

char increaseChar(char start)
    static const int charsInAlphabet=strlen(alphabet);
    int const index=std::find(alphabet,alphabet+charsInAlphabet,start);
    if(!alphabet[index]) // character not found
        return start;
        int const nextIndex=(index+1)%charsInAlphabet;
        return alphabet[nextIndex];

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pliniusAuthor Commented:
Thanks all for your answers.
rstaveley, this wasn't exactly what I ment, but thanks anyway.
I used anthony_w's example.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.