Geração aleatória de cadeias
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
char *charStr;
int stringLength;
void genRandom() {
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < stringLength; ++i) {
charStr[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
}
charStr[stringLength] = 0;
}
int main()
{
while(true)
{
genRandom();
cout < charStr;
}
return 0;
}
O problema surge quando você o compila. Ele irá compilar muito bem, mas nada será exibido e o programa deixará de ser executado. Então, minha pergunta é: o que há de errado com esse código?