Code:
PHP Code:
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <fstream>
using namespace std;
//pass filename to function instead of always using static name
void gen_passwords(char * filename)
{
/*if i were you i'd take away the * before chars and make all the letters in single quotes also i'd avoid using some of the characters you have in this array in a password */
const int numChars = 93; //allows for changes in array size to be made universally
char *pwchars[numChars] = {
"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","1","2",
"3","4","5","6",
"7","8","9","0",
"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","~","`",
"!","@","#","$",
"%","^","&","*",
"(",")","-","_",
"=","+","[","]",
"{","}",";",":",
"|","?",">","<",
".",",","'"," ",0 };
int length,numofpass; //more meaningful identitfier
ofstream pwfile(filename); //i moved this up because usually you should try to keep variable declarations together
srand(time(NULL)); //initialize random number generator
cout<<"Password's length to be generated"<<endl;
cin>>length;
cout<<"Number of Passwords to generate"<<endl;
cin>>numofpass;
for(int i = 0; i < numofpass; i++) //for loop over while
{
for(int j = 0; j < length; j++) //once again for over while
{
pwfile<< pwchars[(rand() % numChars)]; //do random inside []'s to avoid wasting a variable
}
cout<<""<<endl; //what is reason for this line?
}
pwfile.close();
}