I am trying to use a function to generate a char[]
:
char* randString(){
const int len = 5;
char s[len] = {0};
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int stringLength = sizeof(alphanum) - 1;
for (int i = 0; i < len; ++i) {
s[i] = alphanum[rand() % stringLength];
}
return s;
}
the result is random and expected at return s
+ s 0x002df990 "XnQWp... char[5]
however, when i look at the value here:
char* rand = randString();
it contains strange values:
+ rand 0x002df990 "XnQWpÌÌÌÌÌÌÌÌÌÌÌ\x5" char *
did I do something wrong in the return?