Looks like there is a pattern here:
if(digitArray[0]==123){ // i designed it like stopwatch, if like when second is 60, you make it 0 and increment minute by 1
digitArray[0]=97; // 97 is the character 'a' in ASCII table, 122 is the 'z'
digitArray[1]++;
}
// HELP HERE, PLEASE!
//
// my program loops itself after this, copy paste doesn't look cool. how can i improve this part? that 4 in the digitArray[4] is maximum passwordlenght
// im working on this like nonstop 6 hours and still couldnt find a solution...
if(digitArray[1]==123){
digitArray[1]=97;
digitArray[2]++;
}
if(digitArray[2]==123){
digitArray[2]=97;
digitArray[3]++;
}
The generic form of the pattern is:
if (digitArray[x] == 123)
{
digitArray[x] = 97;
digitArray[x + 1]++;
}
Except for the last case. I'll let you figure out how to put in into a for
loop.
Edit 1: creating passwords from 'a' to 'zzzzzz'
This is much like counting in base 26 or base 27 (depending on if you count spaces).
Let's consider adding. Assuming that the letters 'a' to 'z' are contiguous.
std::fill(&digitArray[0], &digitArray[sizeof(digitArray)], ' '); // Initialize
unsigned int last_digit_index = sizeof(digitArray) - 1U;
if (digitArray[last_digit_index] == ' ')
{
digitArray[last_digit_index] = 'a';
else
{
++digitArray[last_digit_index];
}
There is a problem here and that is handling overflow, otherwise known as carry.
For overflow, the digit needs to be reset to ' ', and the next (or previous) digit needs to be incremented.
The above code takes care of incrementing the value, so only the index needs to be changed.
Changing of the index and looping (or recursing) is left as an exercise for the OP.