-
help pls
char name[]="abcdefghijklmnopqrstuvwxyz0123456789";
char password[6];
srand (time(NULL));
for (int i=0;i<6;i++)
{password[i]=name[rand()%37];
}
cout<<"Your password is:";
for (int y=0;y<6;y++)
{cout<<password[y];}
how to loop it for different length of password?
-
-
Try creating the array for the password on the heap.
example:
Code:
int size = 0;
char *password = NULL;
cout << "Enter a size: ";
cin >> size;
password = new char[size];
if(letters == NULL)
{
cout << "allocation failed !" << endl;
return 1;
}
// free up memory when done
delete [] password;
password = NULL;