We are in the year 2017 now. There is no more need to use dynamic arrays, we have strings and vectors and....
Have a look at this demo using modern C++.
Code:
#include <iostream>
#include <string>
std::string randomString(const size_t size)
{
const std::string chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
std::string retval(size, ' ');
for (size_t i = 0; i < size; i++)
{
retval[i] = static_cast<char>(chars[rand() % chars.size()]);
}
return retval;
}
int main()
{
std::cout << "Enter the number of characters the string should contain: ";
size_t size;
std::cin >> size;
std::string s = randomString(size);
std::cout << "Your string: " << s << "\n\n";
return 0;
}
Enter the number of characters the string should contain: 17
Your string: PhQGHuMEAyLnLFDxF