I need some help with my code.
It is a random string generator which works perfect.
However there is one problem.
I want to get the string in my memory using
cin, getline, scanf, or whatever, but that
doesn't work. Can someone tell me how to get
the string I generated and how to store it in a variable?
// If you use C's char arrays:
char String[128] = {0};
for(unsignedint i = 0; i < 21; ++i)
{
String[i] = genRandom();
}
// If you use C++'s std::string:
std::string Str;
for(unsignedint i = 0; i < 21; ++i)
{
Str += genRandom();
}
Also pointing out:
1 2 3 4
return alphanum[1+(rand()%sizeof(alphanum)) % stringLength];
// Because of this, the very first character will never be taken/used/printed
// Use this instead, which is also faster:
return alphanum[rand() % stringLength]