I'm trying to create a random string generator. I create a random length from 1 - 50 with this
randomLength = rand() % kMaxRandomString + kMinRandomString;
then, I create a char pointer with new
to hold it like this:
char* stringBuff = new char[randomLength];
After all that put together I created a vector to hold all possible characters. The whole block of code together looks like this.
void randomStringGen(char * pString)
{
vector <string> alphaChar
{
R"(ABCDEFGHIJKLMNOPQRSTUVWXYZ)",
R"(abcdefghijklmnopqrstuvwxyz)",
};
int randomLetterRow = 0;
int randomLetterColm = 0;
int randomLength = 0;
srand(time(NULL));
randomLength = rand() % kMaxRandomString + kMinRandomString;
char* stringBuff = new char[randomLength];
string test;
for (int i = 0; i < randomLength; i++)
{
randomLetterRow = rand() % 2 + 1; //this chooses a row (lowercase or upper)
randomLetterColm = rand() % 26 + 1; //this chooses a random letter from the row
*stringBuff = alphaChar[randomLetterRow][randomLetterColm]; //I try to add the letter to the string
}
pString = stringBuff;
}
Everything seems to work, except for
*stringBuff = alphaChar[randomLetterRow][randomLetterColm];
Which is the whole important part. I've tried countless ways to do it. I tried with strcpy(), I tried just using a char array[].