generator haseł i taki mały problem, potrzebuje zeby hasła były wyswietlane w kolumnach kolo siebie przykładowo:
powiedzmy ze generujemy 9 haseł po 6 znaków
teraz wygląda to tak:
hasło: 222222
hasło: 222222
hasło: 222222
hasło: 222222
hasło: 222222
hasło: 222222
hasło: 222222
hasło: 222222
hasło: 222222
a potrzebuje zeby wyglądało jakoś tak
222222 222222 222222
222222 222222 222222
222222 222222 222222
kod porgramu
dałby radę ktoś go z edytować odpowiednio ?
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
void generate ( int length ) {
short int rndcnt, rndcurr;
rndcnt = 3+(rand()%3);
char alphas [] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char alphab [] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char digit [] = {'0','1','2','3','4','5','6','7','8','9'};
char other1 [] = {'.',',','?','!'};
char other2 [] = {'@','#','$','%'};
for ( ; length > 0; length-- ) {
short int rnddict = 1+(rand()%rndcnt);
switch(rnddict) {
case 1:
cout<< alphas [ rand() % 25 ];
break;
case 2:
cout<< alphab [ rand() % 25 ];
break;
case 3:
cout<< digit [ rand() % 9 ];
break;
case 4:
cout<< other1 [ rand() % 3 ];
break;
case 5:
cout<< other2 [ rand() % 3 ];
break;
}
}
}
int main() {
short int pass_num = 0;
short int length;
char szInput[20];
do {
cin.clear();
cout << "Ile chcesz wygenerowac hasel? (max 250) : ";
cin >> szInput;
pass_num = atoi(szInput);
} while(!(pass_num) || pass_num>250);
do {
cin.clear();
cout << "Z jakiej ilosci znakow ma skladac sie haslo? (max 250) : ";
cin >> szInput;
length = atoi(szInput);
} while(!(length) || length>250);
cout<<endl<<endl;
cout<<"TWOJE HASLA TO : "<<endl;
for(int i=0; i<pass_num;i++) {
cout<<"Haslo "<<(i+1)<<": ";
generate(length);
cout<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}